I’m trying to use reflection to get the name of cl...
# getting-started
e
I’m trying to use reflection to get the name of classes extending a sealed class, but I always get the name of the sealed class (
ConnectionState
). Here’s my code:
Copy code
public sealed class ConnectionState() {
        var name = ConnectionState::class.simpleName ?: "null"

        object Isolated : ConnectionState()
        object Advertising : ConnectionState()  
        object Discovering : ConnectionState()
   }
Any advice?
r
use
val name: String = javaClass.simpleName
e
The symbol
javaclass
isn’t recognized.
r
Are you not running on the JVM?
e
I’m running on Android.
r
Sorry, it should be camel case:
javaClass
e
It worked perfectly. Thank you!
👍 1