Anonymous classes cannot be safely named by name, but only by instance. You can predict the name and use it, but not too elegantly or reliably.
private void neverCalled() {
SomeInterface si = new SomeInterface() {
};
}
Class anon = Class.forName(getClass()+"$1");
It is much easier to give the class a name and use it. Many IDEs make it easy to change from one to another.
source
share