Details
-
Type: New Feature
-
Status: Closed
-
Priority: Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
The default constructor is usually needed for projects of this type. A simple way to get around it is to use:
Class[] noArgs = new Class[0];
Class objectClass = ...;
while( objectClass != null )
Constructor constructor = objectClass.getConstructor(noArgs);
if( constructor == null )
objectClass = objectClass.getSuperclass();
}
now you have the default constructor for the object - every object has one, just not accessible in the normal way.
Having problems...
I can easily get reference to the Constructor of java.lang.Object but standard reflection will only let me use that to instantiate an instance of Object.
I think I might be missing something - could you tell me how I can use the constructor of object to instantiate a different class?
The approach I'm currently using is similar to this (in SunObjectReflectionFactory), which uses sun.reflect.ReflectionFactory to do a similar thing. It works well, but only on SunJDK1.4.
Can you get this to work using pure reflection?