Possible Duplicate:
@SuppressWarnings for “extends String”
Why T extends String is allowed but gives warning?
The type parameter T should not be bounded by the final type String. Final types cannot be further extended
public class Car<T extends String>
I Know what is final I know It is valid because only possible value of T can be String I was wondering about Warning.
If the actual question is “why it’s allowed”, then imagine a situation when you add
finalkeyword to existing class. I think you don’t want this change to break other exisisting code that uses this class as a generic bound, because it’s still perfectly legal. That’s why compiler does not emit an error in this case.From the other side, you want to be informed if you accidentially use
finalclass as a generic bound, because such a constuct doesn’t make sense. That’s why compiler emits a warning.Actually, it’s a common practice to mark legal but meaningless constructs with warnings.