I have a pretty short question about an extension function that would help clear some of my code. Basically I have some transformations on the hashCode of a class name and I want an extension function to do the transformations.
Example:
Getting the name hashCode: StateA::class.java.name.hashCode()
where StateA is a simple class.
I want to the extension function like:
fun Class<*>.transformName(): String {
var hashString = this.javaClass.name.hashCode()
//Do my stuff on that hashString
return hashString
}
But this doesn't seem to work. When I apply the extension function with StateA.transformName()
, the function gives me an error with Unresolved Reference.
I tried various things like applying the function to StateA::class
or having the hashString equal to this::class.java.name.hashCode()
but nothing works. Any tips?
StateA
is not a type of Class.StateA::class.java
is a valid Class type object. – AndersonandertStateA::class.java.transformName()
would work – Attestationthis.name.hashCode()
– Race