Why calling method with generic return on a generic class is considered unsafe by javac?

后端 未结 4 1680
南笙
南笙 2020-12-06 16:42

Consider the following code:

public class Main {
    public static class NormalClass {
        public Class method() {
            return Inte         


        
4条回答
  •  自闭症患者
    2020-12-06 17:02

    The type of a constructor (§8.8), instance method (§8.4, §9.4), or non-static field (§8.3) M of a raw type C that is not inherited from its superclasses or superinterfaces is the raw type that corresponds to the erasure of its type in the generic declaration corresponding to C.

    Java Language Specification

提交回复
热议问题