Problem with Iterator class
I have created a class 'Gerbil' and then created a hash set of the same class in class 'Program
-----------------------------------------
class Gerbli
{
//Contents of class
}
class Program
{
Set<Gerbil> hs = new HashSet<Gerbil>();
void addtoHashSet(Gerbil obj)
{
hs.add(obj);
}
void get()
{
Iterator itr = hs.iterator();
while(itr.hasNext())
{
Gerbil obj=itr.next();//--->ERROR
}
}
}
------------------------
but while compiling the code, the compiler is giving an error at statement
Gerbil obj=itr.next();
Error: incompatible types
found : java.lang.Object
required: Gerbil
-------------------------
But when I tried with 'getClass' method on itr.next(), it returns 'Gerbil class'
Messed:confused:
Please help:mad:
Thanks!!!