https://kotlinlang.org logo
#announcements
Title
# announcements
k

karelpeeters

12/08/2017, 11:53 AM
Because it can also be used in
when
and
for
statements, where it has a slightly different meaning.
s

snrostov

12/08/2017, 11:55 AM
Hmm... Makes sense. Thanks.
But on the other hand, by defining
operator fun T.contains(other: U)
, we are overloading only in it’s
infix fun
meaning, and not in meaning that
in
is treated in
when
and `for`…
k

karelpeeters

12/08/2017, 12:07 PM
The
in
in
for
actually uses the
iterator
operator, so that isn't affected either way.
Can you even define a function
in
yourself? I'd think it was a reserved keyword.
s

snrostov

12/08/2017, 12:11 PM
Actually yes, but it breaks compileer in some way
Copy code
class A
class B

infix fun A.`in`(x: B) = true

fun main(args: Array<String>) {
  val a = A()
  val b = B()
  println(a in b)
  println(a `in` b)
}
here
println(a in b)
causes
Unresolved reference
Ah, no, all is ok
k

karelpeeters

12/08/2017, 12:12 PM
Isn't that expected because the is no in operator?
s

snrostov

12/08/2017, 12:12 PM
yes, my bad
2 Views