Cannot make a static reference to the non-static type
Post by:Meg Berg
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:
Post by:Steve Luke
What is the exact error message you get? What are the package and import statements you use at the top of the classes?
Post by:Jelle Klap
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.
Post by:Campbell Ritchie
Why are you using compareTo and not equals() in your equals() method?
This thread has been viewed 1456 times.
All times above are in ranch (not your local) time.
The current ranch time is Dec 09, 2018 13:02:24.