如果它的参数是Object ... objects
.
我的构造函数:
public MyClass ( Object ... objects )
{
if ( ! ( objects == null ) )
{
if ( objects.length > 0 && objects [ 0 ] instanceof Long )
{
setLatency ( ( Long ) objects [ 0 ] ) ;
}
}
}
我现在如何得到它:
Class< ? > clazz = Class.forName ( "MyClass" ) ;
Constructor< ? > clazzConstructor = clazz.getConstructor ( Object [ ].class ) ;
我尝试做的事情:
Long latency = 1000L ;
MyClass myInstance = ( MyClass ) clazzConstructor.newInstance ( latency ) ;
我得到 java.lang.IllegalArgumentException: argument type mismatch
如果延迟 == null,则一切正常。