• Post Reply Bookmark Topic Watch Topic
  • New Topic

Note: X.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.  RSS feed

 
W Wilson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So. Here's the deal. I have this ListInterface class that has operations for my linked list and a LList class. The Llist and ListInterface classes are perfect (as I didn't create them, someone professional did). My job is to create a driver, or a demo class that showcases these operations. That being said, heres the driver so far:







The problem is, when I try to compile the driver, I get the following error:



And when I run it just returns:

LList@15db9742LList@15db9742


I use jGRASP. Any idea what I'm missing?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are getting the messages:
Note: DriverWilson.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Simply because you didn't instantiate the object to a type -> LList<String> a = new LList<>();

Next to get each node from the list you must iterate the list using the mechanisms provided:
 
W Wilson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:You are getting the messages:
Note: DriverWilson.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Simply because you didn't instantiate the object to a type -> LList<String> a = new LList<>();

Next to get each node from the list you must iterate the list using the mechanisms provided:


As for those messages: Yeah I realized that and forgot to edit and mention that I changed that. Question about that; ListInterface<String>, that doesn't limit my Linked List to string types only right? Isn't it the LList<> that manages that (and because it's empty means it has no type right?)

As for the loop: Ah right. I don't know why I was trying to use variables from another class instead of the methods. Follow up question. At the top there, I have a loop that's meant to print out the LL. The reason for this is because I wanted to show how the object created has nothing, and that I manually add each element to the LL, and then I print it again showing that they were successfully added. Is it possible to print an empty LL this way or is it not possible due to the fact of having to go through the LL sequentially?

Side note: Is there a way with the for loop to make it so it adds each element onto the same line; so that it would appear as "This is a test message" instead of each element on it's own line? Or again is this a fault because of it doing another "System.out.println" for each iteration in the LL's sequence?

And a final additional question to wrap up: When I add or remove an element from my list, how can I display the element's position?

Appreciate the help by the way.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
W Wilson wrote:As for those messages: Yeah I realized that and forgot to edit and mention that I changed that. Question about that; ListInterface<String>, that doesn't limit my Linked List to string types only right? Isn't it the LList<> that manages that (and because it's empty means it has no type right?)

The current implementation of the interface will allow you to store any object type into the list... If no type is specified then it reverts to a generic type which is unsafe...

W Wilson wrote:Is it possible to print an empty LL this way or is it not possible due to the fact of having to go through the LL sequentially?

If a list is empty then there isn't anything to print...

W Wilson wrote:Side note: Is there a way with the for loop to make it so it adds each element onto the same line; so that it would appear as "This is a test message" instead of each element on it's own line? Or again is this a fault because of it doing another "System.out.println" for each iteration in the LL's sequence?

This can be done by simply changing the statement to System.out.print();

W Wilson wrote:And a final additional question to wrap up: When I add or remove an element from my list, how can I display the element's position?

That can be done by simply reviewing the implementation to see what your options are...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!