H
Henry Townsend
I've kind of backed into generics ... I was developing in
Eclipse using JDK 1.4 with quite a lot of classes which extend
Collections. At some point I started running with JDK 1.5 but Eclipse
was still set to compile in 1.4 compatibility mode. Then I wanted to
make some use of the new printf capabilities and had to allow Eclipse to
compile in "new" (1.5) mode to get it. As a result, I suddenly have LOTS
of warnings being generated by the old-style use of Collections with
casting, such as:
"Type safety: The method add(Object) belongs to the raw type ArrayList.
References to generic type ArrayList<E> should be parameterized."
I'm trying to study up on generics now that I'm in the brave new(ish)
world of JDK 1.5. But in the meantime I'd like a little help trimming
down the huge set of warnings. I can't quite figure out the pattern for
subclassing a Collection; all the tutorials I've found focus more on
writing new code using generics.
So, if I have a simple class:
public class Foo extends ArrayList {
public boolean add(Object o) {
// do something extra
return super(o);
}
}
with some methods overridden and some not (as above), could someone
please show me all the places to put <E> and so on to make Eclipse be
happy again, at which point I can learn generics under a little less
pressure?
TIA,
HT
Eclipse using JDK 1.4 with quite a lot of classes which extend
Collections. At some point I started running with JDK 1.5 but Eclipse
was still set to compile in 1.4 compatibility mode. Then I wanted to
make some use of the new printf capabilities and had to allow Eclipse to
compile in "new" (1.5) mode to get it. As a result, I suddenly have LOTS
of warnings being generated by the old-style use of Collections with
casting, such as:
"Type safety: The method add(Object) belongs to the raw type ArrayList.
References to generic type ArrayList<E> should be parameterized."
I'm trying to study up on generics now that I'm in the brave new(ish)
world of JDK 1.5. But in the meantime I'd like a little help trimming
down the huge set of warnings. I can't quite figure out the pattern for
subclassing a Collection; all the tutorials I've found focus more on
writing new code using generics.
So, if I have a simple class:
public class Foo extends ArrayList {
public boolean add(Object o) {
// do something extra
return super(o);
}
}
with some methods overridden and some not (as above), could someone
please show me all the places to put <E> and so on to make Eclipse be
happy again, at which point I can learn generics under a little less
pressure?
TIA,
HT