I have a generic Link class (for implementing a linked list), as shown below:
class Link<T> { protected T next; public T getNext() { return next; } public void setNext(T newnext) { next = newnext; } }
Now I want another class called Card to inherit from this.
class Card extends Link { ... }
However, I want it to return a Card object for getNext (). How to do it?
The Link class was not originally generic, but then I had to cast getNext () every time I wanted to use it. I had a seemingly problem with a null pointer, so I wanted to fix this.
source share