Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic Interface takes self as Parameter. Recursive Generic? [duplicate]

Tags:

Disclaimer: I don't have a whole ton of experience with Java Generics, but my colleagues and I just spent a solid hour trying to decipher an interface that was structured like this:

interface HasAttributes<A extends HasAttributes<A, B>,                          B extends HasAttributesType<B>> extends Identification<B> { 

What exactly does it mean when an interface generic takes a type parameter that is itself? What does this do?

like image 545
Daniel Bingham Avatar asked Aug 25 '09 20:08

Daniel Bingham


1 Answers

There is meaning to this - Java's Enum class is a good example of a simliar situation:

public abstract class Enum<E extends Enum<E>>     implements Comparable<E>, Serializable 

There are some enlightening answers in this Stack Overflow question about Enum that should shed some light on this particular use of generics for you, as well as answer this more elegantly than I could.

like image 52
Joshua McKinnon Avatar answered Sep 20 '22 20:09

Joshua McKinnon