How can I give a class as a parametre in a method that I can then make one like that:
Type obj = new Type();
is that possible?
How can I give a class as a parametre in a method that I can then make one like that:
Type obj = new Type();
is that possible?
Yes it is possible:
MyClass.class
Let's say you have this method:
private void doSomething(Class cls) {}
you'd call with
doSomething(MyClass.cls);
You can do it different ways.
Pass a string parameter with full ClassName:
void someMethod(String className) { // className like "com.mypackage.Type"
Type obj = (Type)Class.forName(className).newInstance();
}
Pass a Class type:
void someMethod(Class clazz) { // clazz is Type.class
clazz.newInstance();
}