Hello!! I’m trying to get an objects class by its ...
# announcements
c
Hello!! I’m trying to get an objects class by its class name and its throwing a class not found exception
Copy code
Class.forName("com.mystuff.stylopoc.core.Features.Login")
I think its worth noting that the object, Login, is internal to a sealed class, Features Any ideas?
s
Try
com.mystuff.stylopoc.core.Features$Login
👆 1
n
besides just knowing, or reading the spec, if you look in your jar file or wherever .class files are generated, you can see the name of the class from the .class filename
c
I tried looking at the decompiled kotlin file, but totally missed the dollar signs on the companion objects and that object lol
That worked!! This might be left field relative to this questions, but I’m playing with annotations right now and I’m getting the class name by passing the class reference through an annotation. The only way I know how to get the reference back out is by doing janky stuff to convert the parameter of the annotation into a
typeMirror
, then into a string that represents the class name. The string, however, has a dot rather than a dollar sign for the class name. Any clue how I could fix this?
i guess I could write a small tool that just tries different permutations of dots switched out with dollar signs until I get a class out lol. I dont like that solution, but it is a solution
e
.
is for packages (it's actually a
/
in the JVM internally). within a classname, nesting always uses
$