Could any one help me in solving this issue of using generic in inheritance?
here, what I am trying to do is defining a generic ArrayList in my supper class and
reusing the ArrayList in my sub classes.
import java.util.*;
class Test
{
int x;
ArrayList<? extends Test> thing;
public Test(int x)
{
this.x=x;
}
int getX()
{
return x;
}
}
class Testme extends Test{
Testme(int x)
{
super(x);
thing=new ArrayList <Testme>();
}
void addme()
{
thing.add(new Testme(3));
}
void print()
{
System.out.print(thing.getX());
}
}
I get two compile time errors
cannot find symbol
symbol : method add(Testme)
location: class java.util.ArrayList<capture#684 of ? extends Test>
thing.add(new Testme(3));
^
and
cannot find symbol
symbol : method getX()
location: class java.util.ArrayList<capture#49 of ? extends Test>
System.out.print(thing.getX());
Any Ideas please?
Thanks in advance

New Topic/Question
Reply



MultiQuote




|