Hello,
Here is my answer on the question1:
- You should instantiate an object of your class.
- Next you should add this object to the list.
- Now it is a list item.
- To retrieve and see the content of your object, you need to cast this
list item to your class explicitly:
MyOwnClass own = new MyOwnClass("DaveB");
LinkedList myVeryOwnList = new LinkedList();
myVeryOwnList.add(own);
MyOwnClass own1 = (MyOwnClass) list.get(0);
System.out.println("At first position before adding a second MyOwnClass
object: " + own1.getName().toString());
--
I don't have any idea about question2.
Regards,
Moria.
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of DaveB
Sent: Sunday, October 04, 2009 7:58 AM
To: Free Java Programming Online Training Course By Sang Shin
Subject: [java programming] Collections Lab 1016 and Xlint:
Hi All:
I have 2 questions on adding MyOwnClass to a Linked List or Array
List...
1. MyVeryOwnList.add(new MyOwnClass("DaveB"));
provides output that looks like:
myownlinkedlist.myowncl...@19821f
Is there a way to access the methods of that object from the Linked
List, Array list etc?
Method in MyOwnClass is a simple getName().
2. When I run the program, all is well.
However, when I Clean and Build to get the dist folder and jars, I get
warning to recompile with the -Xlint:unchecked compiler option. After
including this option in the compiler options for the project, the
output prints warnings for each Linked List add like:
C:\Documents and Settings\Dave\My Documents\MyJava\MyOwnLinkedList\src
\myownlinkedlist\Main.java:33: warning: [unchecked] unchecked call to
add(E) as a member of the raw type java.util.LinkedList
I have looked this up, but I am unclear as to what is an unchecked
call to add(E) means.
Can someone help to explain?
Thx,
DaveB
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---