jghodd:
Thanks.  This also makes sense.  The confusion came about from the requirement 
to mix objects in a list.

DaveB




________________________________
From: jghodd <[email protected]>
To: [email protected]
Sent: Sunday, October 4, 2009 12:27:26 PM
Subject: Re: [java programming] Collections Lab 1016 and Xlint:

....and the simple answer to your first question is "kinda". You have  
to "get" the object from the list in order to call its methods. You  
can do it inline if you like, since the LinkedList is typed (assuming  
you're using at least java 1.5):

myLinkedList.get(x).getName();

This is not recommended though, unless you also check for a  
java.lang.NullPointerException:

String myName = null;
try
{
     myName = myLinkedList.get(x).getName();
}
catch (java.lang.NullPointerException npe)
{
     ....
}

if (myName != null)
{
     ....
}

Jeff

On Oct 4, 2009, at 10:57 AM, DaveB wrote:

>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to