Why does using raw type variables affect signatures without reference to type-parameters? [duplicate]

自作多情 提交于 2019-11-29 06:13:18

The JLS bit that says this (a bit unclearly) is in JLS 4.8:

The type of a constructor (§8.8), instance method (§8.4, §9.4), or non-static field (§8.3) 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.

So, since rawAlpha is a raw type, the type of rawAlpha.intList is the erasure of List<Integer> intList(). That erasure is List intList().

As for why, I don't have a citation handy, but raw types are only really in Java for backwards compatibility. That means they only need to work as well as they did before generics; what you're asking for is for code that works just a little bit better that it used to. It's not unreasonable, but it's not what they decided on. :-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!