Mr. Boy
Mr. Boy

Reputation: 63728

Get Class for inner class

package test.abc;

public abstract class Base {
 ...
 public static class ChildInner extends Base {
  ...
 }
}

When I call Class.forName("test.abc.Base.ChildInner") I get ClassNotFoundException. What's going wrong?

Upvotes: 4

Views: 1295

Answers (1)

Brian Agnew
Brian Agnew

Reputation: 272277

Have you tried test.abc.Base$ChildInner ?

The inner class name is fully qualified by the outer class name, and the inner/outer distinction by the $ symbol.

Note that this is how the compiler names and saves those inner classes when compiling. You'll see them in your filesystem amongst your classes.

Upvotes: 7

Related Questions