• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Generics: Clashes after Erasure  RSS feed

 
Greenhorn
Posts: 1
Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I couldn't find what the below section mean?


The generics specification cites another rule: "To support translation by erasure, we impose the restriction that a class or type variable may not at the same time be a subtype of two interface types which are different parameterizations of the same interface." For example, the following is illegal:


class Calendar implements Comparable<Calendar> { . . . }
class GregorianCalendar extends Calendar implements Comparable<GregorianCalendar> { . . .
} // ERROR




Anybody please explore it. Thanks in advance.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ashvini sharma wrote:I couldn't find what the below section mean?

Well, I presume you understand the definitions
class Calendar implements Comparable<Calendar> { . . . }
class GregorianCalendar extends Calendar implements Comparable<GregorianCalendar> { . . . }


All it's saying is that you can't implement two different versions of the same interface (don't forget, Comparable<GregorianCalendar> is NOT a subclass of Comparable<Calendar>).

In practise, it doesn't really make much difference, because you can always do something like:
class Calendar<T extends Calendar> implements Comparable<T> { . . . }
class GregorianCalendar extends Calendar<GregorianCalendar> { . . . }


HIH

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!