Java generics type parameter hiding

后端 未结 2 1220
北海茫月
北海茫月 2021-01-06 02:21

I\'m defining a class:

class Foo> {
}

the compiler is complaining about I being

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-06 02:50

    Don't make the inner class parameterized:

    class Baz> {
       class Foo {
       }
    }
    

    As an inner (non-static nested) class, I as defined in the Baz declaration will still have meaning in Foo, since every Foo will have an implicit reference to its outer Baz instance.

提交回复
热议问题