Shoe a inner class ShoeFactory:
public class ShoeFactory {
public static class Shoe {
private String name;
private Shoe() {
}
private Shoe(String name) {
this.name = name;
}
}
public static Shoe createShoe(String shoeName) {
return new Shoe(shoeName);
}
}
, , .... reflection:
public class SmellyShoe {
public static void main(String[] args) {
try {
java.lang.reflect.Constructor c = Shoe.class.getDeclaredConstructors()[0];
c.setAccessible(true);
Shoe smelly = (Shoe)c.newInstance(null);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}