   javac
  Using javac to compile an applet and am getting some bizarre warnings.First of all, the program compiles with zero errors, but I get a messaged saying that the program has unchecked or unsafe operations, and that I should "recompile with the -Xlint flag unchecked." So I enter the following in at the command prompt:javac -Xlint myProgram.javaNow I get like 100 warnings. They all complain about my use of LinkedList and ArrayList methods.For the LinkedList methods, when I go to replace a node in the list with another node - using the .set() method - I get:"Unchecked call to set(E) as a method of raw type java.util.LinkedList"And for the ArrayList methods, when I try adding to the array list using the .add() method, I get:"Unchecked call to add(E) as a method of raw type java.util.ArrayList"What is this mysterious 'E'? Why am I getting these warnings? What should I be checking for that the compiler says in unchecked?Some sample code:[source lang="java]// Example of my .add() method for ArrayListArrayList al;short temp[5] = {1,2,3,4,5};int i;for(i = 0; i < 5; i++)    al.add(temp);// Example of my .set() method for LinkedListLinkedList list = new LinkedList();ListIterator iter = list.listIterator();// Pretend I populate the linked list with a collection of 'Widget' instancesWidget stepNode = new Widget();while(iter.hasNext()){    stepNode = iter.next();    if( /* whatever it doesn't really matter what the conditional is */ )    {   tempWidget.x_val = 4;    }    else   tempWidget.x_val = 20;    iter.set(tempWidget); // This example may not make a whole lot of sense // as I am making it up on the fly but it represents // exactly the way I am using the set() method.}
  I know this isn't what you're asking...but why create a new List class when there are so many included with Java?Another OT question I have...why do you create an instance of class Widget that you don't use?  You should do this:  Widget stepNode = null;instead of this:  Widget stepNode = new Widget();   ;  MattMan - totally lost [crying]What do you mean I am creating a new class of lists? I thought I was simply declaring a new instanced of LinkedList and ArrayList - I am not trying to extend the LinkedList or ArrayList.....is that what I'm doing? I don't think so....   ;  Sorry, I didn't realize LinkedList was one of the many List classes in Java...I thought you were trying to create your own LinkedList class.  My mistake! :P  In that case, I haven't used it before, so I don't know how much help I can be there.However, your declaration of your Widget instance should still be initialized to null.  Otherwise, you're taking up heap space and immediately dereferencing it in the first line of your while-loop, so it sits there waiting to be cleaned up by the garbage collector.   ;  Doesn't that have something to do with generics in 1.5?  I haven't really used 1.5 too much, but don't you have to specify the type when you declare your ArrayList?ArrayList<SomeType> myList = new ArrayList<SomeType>();Or something like that.   ;  what is the difference between:Widget stepNode = null;and:Widget stepNode = new Widget();I guess what I'm asking is: what is the litmus test I should be using with Widgets in order to determine when I should - and shouldn't - use the new keyword to allocate a new Widget or just set it to null?   ;  Oh, I just realized why you might be getting the initial warning.  It's probably due to lack of type-casting.  When you add an object to a List class within Java, it is stored as superclass "Object".  When you retrieve an object from the list, it needs to explicitly be cast to whatever it is intended to be used as.So, where you have this:   stepNode = iter.next();I believe you need to have this:   stepNode = (Widget) iter.next();Let me know if that's what the problem is...   ;  In java 1.5 they introduced generics.  So now rather than having a Collection of objects and having to keep casting them to correct type you can now have a Collection containing only one concrete type.  All those warnings about unchecked types are because you are using an collections of any type (object) rather than one of the correct type.  So rather than declaring your LinkedList as:LinkedList list = new LinkedList();you should have it as:LinkedList<Widget> list = new LinkedList<Widget>();Similarly for your iterator it's not just any old iterator, it's a Widget iterator so you declare it as ListIterator<Widget>.  But seems as you are using 1.5 you don't need to mess about with iterators anymore.  You can just do:LinkedList<Widget> list = new LinkedList<Widget>();...for (Widget stepNode : list){   // do stuff with stepNode};Quote:Original post by necromancer_dfIn java 1.5 they introduced generics.  So now rather than having a Collection of objects and having to keep casting them to correct type you can now have a Collection containing only one concrete type.  All those warnings about unchecked types are because you are using an collections of any type (object) rather than one of the correct type.  So rather than declaring your LinkedList as:LinkedList list = new LinkedList();you should have it as:LinkedList<Widget> list = new LinkedList<Widget>();Oohh, I didn't know this was introduced with 1.5.  Thanks for the info, it's new to me! :)   ;  The problem is that you're coding without using Generics with the 1.5 compiler, and not flagging to compile in 1.4 mode. Try using javac -Xlint -target 1.4 myProgram.java and see will that work.   