How to extend Node<T extends Comparable<T>> class

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.

Answers


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.


Need Your Help

Web worker: NotFoundError when I try to read a file created in the main thread

javascript html5 google-chrome web-worker html5-filesystem

In Chrome 32, I've got an JS app where I write raw images from a canvas to a file and I want to close the file and open it for processing in a worker.

How can I modify the background of a ListItem when it has been selected?

java android listview listviewitem

I have a ListView with a bunch of ListItem's. When the user selects an item, I would like to change that ListItem's background to an image. How can I accomplish this?