Solution: Using when

private val magicNumbers = listOf(7, 13) fun name(a: Any?): String = when (a) { null -> "Nothing" 1, 2, 3 -> "Small number" in magicNumbers -> "Magic number" in 4..100 -> "Big number" is String -> "String: $a" is Int, is Long -> "Int or Long: $a" else -> "No idea, really" } fun main() { println(name(1)) // Small number println(name("A")) // String: A println(name(null)) // Nothing println(name(5)) // Big number // (because 5 is in 4..100) println(name(100)) // Big number // (because 100 is in 4..100) println(name('A')) // No idea, really // (because 'A' is Char) println(name("1")) // String: 1 println(name(-1)) // Int or Long: -1 println(name(101)) // Int or Long: 101 // (because 101 is greater than 100, so not in 4..100) println(name(1L)) // Int or Long: 1 // (because 1L is Long) println(name(7)) // Magic number // (because 7 is in magicNumbers collection) println(name(3)) // Small number println(name(3.0)) // No idea, really // (because 3.0 is Double) println(name(100L)) // Int or Long: 100 // (because 100L is Long) }