Instantiate nested static class using Class.forName

Solution 1:

Nested classes use "$" as the separator:

Class.forName("a.b.TopClass$InnerClass");

That way the JRE can use dots to determine packages, without worrying about nested classes. You'll spot this if you look at the generated class file, which will be TopClass$InnerClass.class.

(EDIT: Apologies for the original inaccuracy. Head was stuck in .NET land until I thought about the filenames...)

Solution 2:

try

Class.forName("a.b.TopClass$InnerClass");

Solution 3:

Inner classes are accessed via dollar sign:

Class.forName("a.b.TopClass"); 
Class.forName("a.b.TopClass$InnerClass");