There should be no ambiguity
# announcements
s
There should be no ambiguity
k
What is "ClassName" and what does type inference have to do with reflection?
But companion objects definitely have an associated
KClass
and
Class
, take a look at all the companion related functions, eg. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/companion-object.html.
s
When I write
fn(String)
, it passes the companion object of String to fn
But if we know that fn accepts a KClass or a Class object, it can reliably become a shorthand of
String::class
or
String::class.java
k
That's very brittle: it only works for some classes, adding a companion object becomes a breaking change and it stops working if that
fn
ever gets an overload.
☝️ 1
s
I mean it resolves as two different objects, which is possibly bad, but only when fn supports multiple types or
Any
But in that case the compiler could error for ambiguity