Because it can also be used in `when` and `for` st...
# announcements
k
Because it can also be used in
when
and
for
statements, where it has a slightly different meaning.
s
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
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
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
Isn't that expected because the is no in operator?
s
yes, my bad