1

I am new to Generics (Java). I was following the official Oracle docs and it's mentioned in there:

enter image description here

So, if that is the case, why printList fails but add doesn't?

enter image description here

Am I missing something from the core definitions of two? Pardon me, if this question is too stupid to ask or already is on stackoverflow. Atleast I couldn't find any answer.

SSC
  • 2,956
  • 3
  • 27
  • 43
  • 2
    Type erasure. There are no generics at run time so you cannot have two methods with the same signature. – Boris the Spider Apr 14 '15 at 23:19
  • Okay, I got that there are no generics at runtime but the error is at compile time, right? For compile time, it is correct? – SSC Apr 14 '15 at 23:22
  • 3
    @BoristheSpider This isn't necessitated by type erasure. This type information is, in fact, included in compiled classes. It was a choice by the language designers to ensure safe evolution between language versions. Read the [question/answer](http://stackoverflow.com/questions/1998544/method-has-the-same-erasure-as-another-method-in-type) linked by Hypino. – erickson Apr 14 '15 at 23:23

0 Answers0