How are extension functions handled when two of th...
# announcements
c
How are extension functions handled when two of them are valid? As an example, I'm thinking of adding
Any?.filter
,
Any?.map
etc extension functions, to help with null handling. How would the compiler react if it is used in a file in which
List.filter
(from the standard lib) is called? More precisely, if I write the following, which extension function would be called (assuming both are imported):
Copy code
val l = listOf (...)
l.filter { it... }
In that case they are both valid choices by the compiler, since
List
is also a
Any?
. So, which one is called?
m
Test it? But personally, I hope.the compiler let's you know you have ambiguous definitions. I'd be surprised if it doesn't.