Thiago Sanchez

Greenhorn
+ Follow
since Mar 28, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Thiago Sanchez

:shocked: I forget A DETAIL :shocked:

ad.calldoctor((ArrayList<Animal>) mylist);
//ad.calldoctor(c);


}
//>>>??? Question
public void calldoctor(ArrayList<Animal> animal)//Instead of List if i use
{ //ArrayList its giving me
//compiletime error
//eventhough i am passing Animal
//type reference....??
animal.add(new Dog("Germanshephered"));


}
}
:shocked:
[edit]Disable smilies. CR[/edit]
[ September 19, 2008: Message edited by: Campbell Ritchie ]
16 years ago
public class AnimalDoctorGenric2
{
public static void main(String[] args)
{

List<Animal> mylist = new ArrayList<Animal>(); mylist is not an ArrayList, but a List. The JVM knows that an ArrayList is a List but not all List's are ArrayLists so you can do List<anyList> yourList = new ArrayList<anArrayList> but you can`t do ArrayList<anArrayList> youArrayList = new List<yourList>...

so if you need your List to came an ArrayList again try that:

ArrayList<Animal> anotherList;

anotherList = (ArrayList)myList;



Dog d = new Dog();
Cat c = new Cat();
Animal a = new Animal();
mylist.add(new Cat("Black"));
mylist.add(new Dog("Doverman"));

for(Object o : mylist)
System.out.println(o);

AnimalDoctorGenric2 ad = new AnimalDoctorGenric2();
//ad.calldoctor(d);

or try it
ad.calldoctor((ArrayList)mylist);
//ad.calldoctor(c);


}
//>>>??? Question
public void calldoctor(List<Animal> animal)//Instead of List if i use
{ //ArrayList its giving me
//compiletime error
//eventhough i am passing Animal
//type reference....??
animal.add(new Dog("Germanshephered"));


}
}

Sometimes programming means
16 years ago