Java Generics and numbers

后端 未结 11 1138
离开以前
离开以前 2021-02-05 08:58

In an attempt to see if I can clean up some of my math code, mostly matrix stuff, I am trying to use some Java Generics. I have the following method:

private <         


        
11条回答
  •  耶瑟儿~
    2021-02-05 09:43

    Arrays and Generics do not play well together:

    "Arrays are covariant, which means that an array of supertype references is a supertype of an array of subtype references. That is, Object[] is a supertype of String[] and a string array can be accessed through a reference variable of type Object[] ."

    see the Java Generics FAQ:

    • Can I create an array whose component type is a concrete parameterized type?
    • How do I generically create objects and arrays?

提交回复
热议问题