groostav
01/17/2018, 10:41 PMval x = listOf(1, 2, 3)
val y = listOf("a", "b", "c")
val c: List<Serializable> = x intersect y
which is legal kotlin code, and compiles.
I think this should pretty clearly be a type error, with the compiler complaining with something like no suitable method found 'intersect' for P1<reciever>: List<Int>, and P2: List<String>"
If kotlin had intersect
as a regular extension function instead of an infix fun
, with @kotlin.internal.NoInfer
on its generic parameter, then the above code would indeed be a compiler failure, but it would be about how you need a type for intersect
. This would either force you to select Serializable
as your type --if thats actually what you meant, or, more likely, discover your error from a static compile time failure rather than a runtime failure!
Of course, it also makes the code uglier.