Why are generics completely disabled when you ignore a parameter type?

后端 未结 2 1276
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 03:03

As a followup to this question, first the background

Given a class with this declaration:

public class SomeClass

And a sub

相关标签:
2条回答
  • 2020-12-20 03:23

    It's a weird one. It seems, though, you could always get rid of the error without introducing any problems by extending SomeClass<Object> instead of SomeClass:

    public class SomeSubClass extends SomeClass<Object> {
        ...
    }
    
    0 讨论(0)
  • 2020-12-20 03:33

    I don't quite know the rationale for this, but this behavior is specified in the Java Language Specification JLS S4.8:

    The superclasses (respectively, superinterfaces) of a raw type are the erasures of the superclasses (superinterfaces) of any of its parameterized invocations.

    Given that it's highly discouraged to use Raw types in new code, they wanted to simply the rules for interaction between Raw and Parameterized types I guess.

    0 讨论(0)
提交回复
热议问题