what's the difference between `::javaClass` and `:...
# announcements
x
what's the difference between
::javaClass
and
::class.java
s
I wrote this up back in September, not sure if it still holds true for 1.3
Copy code
// Will default to Foo's companion class if there is one
// otherwise it complains
// "Classifier 'Foo' does not have a companion object and thus must be initialized here"
Foo

// KClass<Foo>
Foo::class

// java.lang.Class<Foo>
Foo::class.java

// don't use this.
// yields some kinda generic `Class<T>` that isn't useful for comparison
Foo::javaClass

// yields the same thing as Foo::class.java, use this on instances
// to match against the class type if you need to
foo.javaClass
// e.g.
when (foo.javaClass) {
  Foo::class.java -> { ... }
}
👍 1
compiled from a few discussions on here and a bit of testing on my part
h
+1 for avoiding
javaClass
, what it resolves to can change depending on class usage
For example I was using
javaClass.getResourceAsStream
in a UI class and it was working fine. When I converted that UI class into a
Fragment
in TornadoFX suddenly none of my resources can be found.
class.java
works in both cases.
n
thanks i learned something today