Go to the documentation for this method here: getDeclaredConstructor ()
I have not seen any references to it returning only public constructors.
My problem is that I have the following code snippet:
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 I run this method for a class that has the appearance of a default constructor (a closed package), I get a MissingMethod exception. Changing the constructor for the public fixes the problem.
source share