Raw types with generic methods independent of the generic type

后端 未结 1 576
青春惊慌失措
青春惊慌失措 2020-12-19 05:53

This a follow-up to chrert\'s question Generic classes with Collection getter of other types. If you can come up with a better title to my question, feel free to edit it:

相关标签:
1条回答
  • 2020-12-19 06:04

    In the first case, raw.getCollection() returns a raw Collection. JLS 14.14.2 specifies the type checking for the enhanced for loop:

    If Type (in the FormalParameter production) is a reference type, then TargetType is Type; otherwise, TargetType is the upper bound of the capture conversion of the type argument of I, or Object if I is raw.

    (emphasis added)

    In the second case, you're explicitly assigning a raw type to a generic type, which is allowed with a warning like normal.

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