On Oct 4, 4:57 pm, DaveB <[email protected]> wrote:
> 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?
Normally, a collection is a set of specific "objects", objects being
specified in the formation of the collection. That is the collection
is a set of elements of given type, the type being specified when
defining the collection.
So, if you define the LinkedList as it is done, your LinkedList does
not specified the type of the elements (aka the "objects") of the
collection.
So, it gives you the warning, E being the element of the collection.
It means that it is not safe (i.e. Java cannot verify) that the
element you add to the collection is of the given type, since you have
not specified a type.
Now you may define the collection this way:
LinkedList<Object> myLinkedList = new LinkedList<Object>();
Notice that you say here that the elements of the collection are of
type Object.
Then you may add safely:
myLinkedList.add(new whatever(args*));
Of course, the example is a little constraint, since you use Object as
type, but you may for example use only String, or only Integer, what
you really want in your collection.
>
> 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
-~----------~----~----~----~------~----~------~--~---