I started to use Java Reflection recently but currently stuck at this.
So I have something like this:
Class<?> dogClass = Class.forName("com.example.dog");
Object dogObject = dogClass.newInstance();
I would like to use the above object in this arraylist:
List<Dog> dogList = new ArrayList();
So in normal case:
for(Dog d : dogList) {
....
....
}
But when I tried to use the java reflection, it doesn't work..
for(dogObject d : dogList) {
....
....
}
Can anyone enlighten me please? Thank you.
forloop iterates over the objects already existing in the list. Where is the relationship to the new object you’ve just created? What do you want to achieve?