There is a way to avoid the slow reflection to create an instance from a class, obviously within another method ? For example:
Foo foo = new Foo();
foo.create(Dog.class, "rocky");
class Foo {
Object create(Class object, String dogName) {
//create an instance of the class 'object' here passing the argument to constructor
//e.g. Object obj = new object(dogName); <-- this is wrong
return obj;
}
}
class Dog extends Animal {
Dog(String dogName) {
this.name = dogName;
}
}
class Animal {
String name;
}
I cannot create the instance using the keyword "new", because I must create the instance in another method in a dynamic way...
You have carte blanche to improve in the best way (like performance) this code :) Thank you!