Java doesn't allow arrays of inner classes for a generic class

前端 未结 3 1574
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-07 12:04

I know that you cannot create an array of a generic type, Instead you have to resort to a hack. (Given Java supports generic arrays, just not their creation, it is not clear to

3条回答
  •  不要未来只要你来
    2021-02-07 12:19

    Is it an option for you to make the inner class static?

    If that is possible you shold be able to create array of the inner class using the standard way:

    public class Outer {
        final Inner[] inners = new Inner[16]; // works
    
        static class Inner {
        }
    }
    

提交回复
热议问题