0

I had a class like

package example.com
class TContract : Contract {
    interface Commands : CommandData {
        class TIssue(val reference: State) : Commands
    }
}

How to get the class reflection of TIssue. I tried Class.forName("example.com.TContract.Commands.TIssue"), but it's not work!

Henry
  • 191
  • 6

1 Answers1

1

Inner classes will be compiled and the class file will be ClassName$InnerClassName. See: https://stackoverflow.com/a/11388863/1048340

You need to escape the dollar sign character in Kotlin. The following will work:

Class.forName("example.com.TContract\$Commands\$TIssue")

Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
  • 1
    Regarding your edit to https://stackoverflow.com/posts/27813407/revisions - my mod flag to get it undeleted was declined with the rather churlish reason of "Then they can use a flag themselves." – TylerH Nov 26 '18 at 21:05