I have a question about generic arguments, this is the code I have:
public <T extends Renderable, Box> void setBackBox(T bb) {
...
}
As you see you can give as parameter bb an object that extends Box & Renderable. But eclipse gives the following waring: 'The type parameter Box is hiding the type Box'.
How can I fix this/work around it?
Here, you're defining two type-parameters:
T extends Renderable
Box
Box
is the alias of the second method-scoped type-parameter and if you have another one with the same name (class-scoped), the method-scoped one will hide it. That's why Eclipse throws a warning.
If you want T
to extend both Renderable
and Box
, you have to do:
public <T extends Renderable & Box> void setBackBox(T bb)
Also note that when your type-parameter(s) extend multiple types, you're allowed to use one class, which has to be first in the list. For example, if Box
is a class, the correct definition would be:
public <T extends Box & Renderable> void setBackBox(T bb)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With