Why do some claim that Java's implementation of generics is bad?

后端 未结 13 1973
挽巷
挽巷 2020-11-29 15:53

I\'ve occasionally heard that with generics, Java didn\'t get it right. (nearest reference, here)

Pardon my inexperience, but what would have made them better?

13条回答
  •  没有蜡笔的小新
    2020-11-29 16:48

    Another side effect of them being compile-time and not run time is that you can't call the constructor of the generic type. So you can't use them to implement a generic factory...

    
       public class MyClass {
         public T getStuff() {
           return new T();
         }
        }
    

    --jeffk++

提交回复
热议问题