https://kotlinlang.org logo
Title
h

hoang

12/02/2021, 8:46 AM
I've got this generic function: https://pl.kotl.in/cv6sdbHHy
my question is why does this compile?
oh should I put the code directly here instead of a playground link?
j

Joffrey

12/02/2021, 8:48 AM
T
is inferred by the compiler, and in your case inferring
Any
makes it work, so the compiler chooses this
(yes if the code is small it's easier to just put it here)
👍 2
If you want to experiment or clarify those things, you can try specifying the type of
T
explicitly, as in:
a.isOneOf<String>(1.2, 3)
And this will fail as you expect
👍 2
h

hoang

12/02/2021, 9:01 AM
oh ok, got it. Thank you.