Forums Register Login
Cannot make a static reference to the non-static type

I am working on using linked lists. My project will include a UI, but I am trying to check that my class is doing what I expect it to but adding a main method and printing to the console. My object is AntiqueInfo and I am using my Node class to manage the list. When I try to add new AntiqueInfo items in the Node class in the main method, I am getting the error: Cannot make a static reference to the non-static type

The same code works in the AntiqueInfo class and I just don't understand what I did in the Node class that makes the AntiqueInfo not static.

Here's my code:

What is the exact error message you get? What are the package and import statements you use at the top of the classes?
(1 like)
This confusion is due to a naming conflict between the type parameter of the Node class and the name of the AntiqueInfo class. It is the type parameter that the main method of the Node class refers to. Try renaming the type parameter of the Node class to T. That will solve the naming conflict and allow you to refer to the AntiqueInfo class by it's simple name from the main method of the Node class. You may have to add an import for the AntiqueInfo class in the Node class first though, depending on whether or not they are in the same package. Please refer to the tutorial section on generic types (and the generics tutorial as a whole) for more information.
Why are you using compareTo and not equals() in your equals() method?
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

This thread has been viewed 1262 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jun 21, 2018 16:08:26.