Java generics type erasure of method parameters

前端 未结 3 745
南旧
南旧 2021-01-02 10:29

I got this one from a google I/O puzzler talk given by Joshua Bloch. Here\'s the code

 public class Glommer {
      String glom(Collection          


        
3条回答
  •  死守一世寂寞
    2021-01-02 10:42

    You can read more about Raw Types to understand it fully

    Basically, raw types are for using legacy code, almost anything in a raw class will become raw itself, in this case those 2 methods.

    So when it is raw there is a method that gets a List and one for Collection so its called the List one, if its not raw, the methods are not raw also and it will call the Collection one because it has the extra information

提交回复
热议问题