First, create the following in a separate file:
public Do_Not_Instantiate_This_Class extends Exception { private static final long serialVersionUID = 1L; }
Then make a constructor in your inner class, which is just
private final innerClass() throws Do_Not_Instantiate_This_Class { throw(new Do_Not_Instantiate_This_Class()); }
Thus, no classes except the outer class can “see” the constructor, and the outer class cannot use the constructor without having to try / catch or throw for Do_Not_Instantiate_This_Class to even compile, and it will always catch or throw it during fulfillment. Not entirely optimal, but I think this is done the way you want.
source share