How I can get constructor reflectively, if its param is Object ... objects.
My constructor:
public MyClass ( Object ... objects )
{
if ( ! ( objects == null ) )
{
if ( objects.length > 0 && objects [ 0 ] instanceof Long )
{
setLatency ( ( Long ) objects [ 0 ] ) ;
}
}
}
How I get it now:
Class< ? > clazz = Class.forName ( "MyClass" ) ;
Constructor< ? > clazzConstructor = clazz.getConstructor ( Object [ ].class ) ;
What I try to do:
Long latency = 1000L ;
MyClass myInstance = ( MyClass ) clazzConstructor.newInstance ( latency ) ;
And I get java.lang.IllegalArgumentException: argument type mismatch
If latency == null, everything works.
newInstance(new Object[]{latency})?newInstance()itself is varargs.