Java Generics and numbers

后端 未结 11 967
离开以前
离开以前 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:32

    Generics and arrays don't match very well. Creating a generic array is not allowed since it would not be typesafe. It stems from the fact that if Sub is a subtype of Super, then Sub[] is a subtype of Super[], which is not the case of generic types; for any two distinct types Type1 and Type2, List is neither a subtype or a supertype of List. (Effective Java covers this in chapter 5, item 25).

提交回复
热议问题