kevinmost
02/01/2018, 7:29 PMin
keyword can be used in a when
for any operator fun contains
, whether it's defined as String.contains
, List.contains
, your own custom type's contains
function, etcadam-mcneilly
02/01/2018, 7:39 PMwhen (charInput) {
in "Adam" -> println("Yay")
else -> println("Nope")
}
kevinmost
02/01/2018, 7:42 PMcharInput in "Adam"
is equivalent to saying "Adam".contains(charInput)
(in all instances, not just in a when
, this is a standard Kotlin operator), so for example, "A" would hit your "Yay" block in this case, but "Adam McNeilly" would hit your "Nope" blockadam-mcneilly
02/01/2018, 7:44 PMcontains
which I didn't know was true. This is neat.