Having a hard time with generic classes and generic methods in java

generics, java

Solution

Your `GenericDictionary` class would need to be generic as well:

public class GenericDictionary<T> ...
{
}

At that point, it'll be fine to use `Node<T>` within the class.

If the interface contains the `add` method, the interface should probably be generic too:

public class GenericDictionary<T> implements Dictionary<T>
{
}

I'd advise against an interface called `GenericDictionary_interface`, by the way... if there's only ever going to be one implementation, you could call the interface `GenericDictionary` and the implementation `GenericDictionaryImpl` - somewhat horrible, but reasonably common. If there are multiple implementations, name the implementation by some differentiating aspect.

Problem

New to java, I did search for examples, but I'm having a really hard time. I have a node class that uses generics: ``` public class Node<T> { private int key; private T data; private Node<T> nextNode; } ``` The node is Okay. ``` public class GenericDictionary implements GenericDictionary_interface { private int capacity; private Node<T> [] slots; public void add (Node<T> newNode) { } } ``` This is how I would write it, I think. I want the GenericDictionary to work with node objects. I get an error: "T cannot be resolved as a Type". Thing is I don't know how it should look like.

Original source