Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Unchecked or Unverified Warning

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unchecked or Unverified Warning

    I am compiling my code and I keep getting an unsafe or unchecked operations warning. I know it is just a warning, but I still need it to disappear without suppressing it. I've researched and it looks like it comes from ArrayList generalizations, but I don't know how to fix it. I've included the relevant portions of code.

    //Variables at the top of class
    	Vector[] adjacency;
     
    //Constructor
     		adjacency = new Vector[N*N];
     		for(int i=0;i<adjacency.length;i++)
     			adjacency[i] = new Vector<Integer>();
    //In a called method - node & neighbor are both ints
     		if(node<neighbor) 
    			 adjacency[node].add(neighbor); 
     		else 
     			adjacency[neighbor].add(node);
     
    //In another called method  - node & neighbor are both ints
    				if(node<neighbor)
    					if(!adjacency[node].contains(neighbor)) {
    						//Add to graph and increase count
    						adjacency[node].add(neighbor);
    						count++;
    					}
    				if(neighbor<node)
    					if(adjacency[neighbor].contains(node)) {
    						//Add to graph and increase count
    						adjacency[neighbor].add(node);
    						count++;
    					}

    Here is the warning I get from the compiler when I ask for details (-Xlint:unchecked)

    travis-mac:Project3 Travis$ javac TMMp3.java -Xlint:unchecked
    TMMp3.java:76: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector
    			 adjacency[node].add(neighbor); 
    			                    ^
    TMMp3.java:78: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector
     			adjacency[neighbor].add(node);
     			                       ^
    TMMp3.java:147: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector
    						adjacency[node].add(neighbor);
    						                   ^
    TMMp3.java:153: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector
    						adjacency[neighbor].add(node);
    						                       ^
    4 warnings

    If you can help me get this warning to go away that would be great!

    Thanks,
    Travis


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Unchecked or Unverified Warning

    Can you generalize your code and post an SSCCE that demonstrates these warnings?

Similar Threads

  1. Unchecked or Unsafe Operations
    By saxophonemaster in forum Collections and Generics
    Replies: 2
    Last Post: April 12th, 2011, 04:40 AM
  2. Warning: Java component download site infected with malware
    By Darryl.Burke in forum AWT / Java Swing
    Replies: 1
    Last Post: January 27th, 2011, 04:19 AM
  3. Applet Security Warning & Class Loaders
    By tess in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 2nd, 2010, 01:41 PM