I'm doing a fair bit of framework-type work and having to work with a lot of Class objects, and to be honest, I'm finding it more cumbersome than I did in Java. Is there an alternative to using javaClass<T>()? It's a verbose operator, and the fact that it has 'java' in the name suggests that it's primary purpose is for java interoperability.
The best I’ve come up with has been to add a property to a class object, which improves the syntax a bit:
class SomeObject() { class object { val clazz = javaClass<SomeObject>() } }
val x = someFunction(SomeObject.clazz)
Ideally, I’d like to be able to require that the parameter be a class object, and that a class object has a way to get the Class. Something like:
// all class objects automatically implement this trait trait ClassObject<T> { val class: Class<T> }
val x = someFunction(SomeObject)
Perhaps the class object, if not defined, would be implied, and that all class objects would automatically implement the ClassObject trait so it would be possible to differentiate them.
Any other thoughts on how to improve this?