I tried to create new files Animal class and DOg class which extends Animal and genericTesting Class which makes use of Animal and Dog class.I am facing problem in using new for loop as per
Java 1.5
import java.util.ArrayList;
import java.util.List;
public class GenericTesting extends Animal {
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
List<? super Dog> animalList= (List<? super Dog>

new ArrayList<Dog>();
Animal animalObject = new Animal();
animalObject.addAllAnimals(animalList);
}
}
DOg Class
public class Dog extends Animal{
}
Animal Class where i am getting compiler error on for loop
import java.util.List;
public class Animal {
public Animal(){
System.out.println("I am animal ");
}
public void addAllAnimals(List<? super Dog> animalList){
animalList.add(new Dog());
for(List<Animal> d : animalList)
{}
}
}
what should be the syntax for ..FOR loop
how do i iterate through animal list which can be dog or animal as i have used wildcard with super keyword
Thanks in advance
Source:My own