Re: Generic Trouble
On 11/12/2010 4:34 PM, Stefan Ram wrote:
Arne Vajh?j<arne@vajhoej.dk> writes:
Why not use<T> in the interface?
If this is the recommended way to deal with a ?rawtype?
warning, when one does not want to restrict the type
parameter to anything more special than ?java.lang.Object?,
ok, I will do it.
I just had read advice before to use ?< ?>? in such cases,
so I already have edited this into dozens of places. Ok,
so now I may go back and change it to ?< T>?. I just want
a general and final solution, so that I will not have to
change this even more often.
I think maybe you misinterpreted Arne's suggestion, or I did.
I take his suggestion as:
interface MyInterface<T> {
void addrac(Comparable<T> container, int position);
}
class MyClassForFoo implements MyInterface<Foo> {
void addrac(Comparable<Foo> container, int position) {}
}
Another alternative, which may work equally well, depending on your
situation, but I doubt it will because of the method signature and lack
of other context in the parameters.
interface MyInterface {
<T>void addrac(Comparable<T> container, int position);
}
class MyClass implements MyInterface {
<T> void addrac(Comparable<T> container, int position) {
T t = container;
}
}
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>