I have an abstract class that is like this:
public abstract class Node<T extends Comparable<T>>
I need extends Comparable<T>
so that I may use .compareTo()
with generic type T
.
I try to extend this class with this sub-class declaration:
public class ListNode<T> extends Node<T extends Comparable<T>>
However this throws SyntaxErrors in eclipse for the second extends
and for the final two >>
.
Is this the way to declare the sub-class? It seems so messy.
public class ListNode<T extends Comparable<T>> extends Node<T extends Comparable<T>>
How should this be done? Cheers in advance.
With Node
as
public abstract class Node<T extends Comparable<T>>{}
ListNode
can be:
public class ListNode<T extends Comparable<T>> extends Node<T>
The key thing to note is that the type parameter after the name of the declared class is what constrains T for everything else in the class. This includes the other types extended by the declared class.
This means that once you have bounded T
you don't need to do it again in the extends
/implements
statements.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments