Going over the documentation for this method here: getDeclaredConstructor()
I could not see any reference of it returning only public constructors.
My problem is that I have the following piece of code:
protected BaseClass internalCreate(String className) throws Exception {
Class<? extends BaseClass> classObj = Class.forName(className)
.asSubclass(BaseClass.class);
Constructor<?> ctor = classObj.getDeclaredConstructor((Class[]) null);
ctor.setAccessible(true);
return (BaseClass) ctor.newInstance();
}
When running this method for a class that has a default constructor visibility (package private), i am getting a MissingMethod exception. Changing the constructor to public fixes the issue.