hi
ich arbeit grad mal wieder an der generellen reflection function von mir. Im moment ist es sicher nicht die perfekte lösung die anzahl der argumente auf 5 zu beschränken, aber mir fällt da keine andere lösung ein.
Die Problematik die ich hab ist dass ich nicht verstehe wieso mir getClass() nicht das erwünschte ergebnis gibt:
Console:
class java.net.URI
class [Ljava.net.URI;
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Jemand ne ahnung wie ich das hindrehen kann dass es passt?
lg
noise
ich arbeit grad mal wieder an der generellen reflection function von mir. Im moment ist es sicher nicht die perfekte lösung die anzahl der argumente auf 5 zu beschränken, aber mir fällt da keine andere lösung ein.
Die Problematik die ich hab ist dass ich nicht verstehe wieso mir getClass() nicht das erwünschte ergebnis gibt:
Code:
public Object getReflectedAlgorithmManager(String className,Object[] objects) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, NoSuchMethodException{
Class aClass = null;
Constructor constructor;
aClass = Class.forName(className);
if(objects.length==0){
// constructor = aClass.getConstructor(new Class[]{});
return aClass.newInstance();
}else if(objects.length==1){
System.out.println(URI.class);
System.out.println(objects[0].getClass());
constructor = aClass.getConstructor(new Class[]{objects[0].getClass()});
return constructor.newInstance(new Object[]{objects});
}else if(objects.length==2){
constructor = aClass.getConstructor(new Class[]{objects[0].getClass(),objects[1].getClass()});
return constructor.newInstance(new Object[]{objects});
}else if(objects.length==3){
constructor = aClass.getConstructor(new Class[]{objects[0].getClass(),objects[1].getClass(),objects[2].getClass()});
return constructor.newInstance(new Object[]{objects});
}else if(objects.length==4){
constructor = aClass.getConstructor(new Class[]{objects[0].getClass(),objects[1].getClass(),objects[2].getClass(),objects[3].getClass()});
return constructor.newInstance(new Object[]{objects});
}else if(objects.length==5){
constructor = aClass.getConstructor(new Class[]{objects[0].getClass(),objects[1].getClass(),objects[2].getClass(),objects[3].getClass(),objects[4].getClass()});
return constructor.newInstance(new Object[]{objects});
}
return null;
}
Console:
class java.net.URI
class [Ljava.net.URI;
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Jemand ne ahnung wie ich das hindrehen kann dass es passt?
lg
noise