Class.forName doesn’t work for nested classes?


#1

Hi, I’m using a Java library (Kafka Streams) that internally uses Class.forName to get a class reference to an inner class.

Maybe I’m missing something, but it seems like maybe Kotlin doesn’t support this?

I tried this in the REPL:

>>> Class.forName("java.util.Map$Entry")
error: unresolved reference: Entry
Class.forName("java.util.Map$Entry")
                             ^

and then I tried it in a Clojure REPL:

user=> (Class/forName "java.util.Map$Entry")
java.util.Map$Entry

Am I missing something? Or is this a bug?

I’m using kotlinc-jvm 1.1.4-3 (JRE 1.8.0_141-b15) on MacOS 10.12.6 (Darwin 16.7.0).

Thanks!
Avi


#2

As described in the documentation the $ character is used in Kotlin for string templates. You need to escape it in this case.


#3

Class.forName("java.util.Map\$Entry")


#4

@yole @madmax1028 thanks so much!