https://kotlinlang.org logo
Title
e

Ellen Spertus

10/03/2019, 7:21 PM
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:
public sealed class ConnectionState() {
        var name = ConnectionState::class.simpleName ?: "null"

        object Isolated : ConnectionState()
        object Advertising : ConnectionState()  
        object Discovering : ConnectionState()
   }
Any advice?
r

Ruckus

10/03/2019, 7:23 PM
use
val name: String = javaClass.simpleName
e

Ellen Spertus

10/03/2019, 7:24 PM
The symbol
javaclass
isn’t recognized.
r

Ruckus

10/03/2019, 7:25 PM
Are you not running on the JVM?
e

Ellen Spertus

10/03/2019, 7:25 PM
I’m running on Android.
r

Ruckus

10/03/2019, 7:26 PM
Sorry, it should be camel case:
javaClass
e

Ellen Spertus

10/03/2019, 7:27 PM
It worked perfectly. Thank you!
👍 1