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 3 of 3

Thread: Unchecked or Unsafe Operations

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

    Default Unchecked or Unsafe Operations

    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
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Unchecked or Unsafe Operations

    Vector[] adjacency;
    Your problem is when you create the array but I'm not sure you can use Generics with arrays. Why not make a Vector of Victors err Vectors? Roger!
    Vector<Vector<Integer>> adjacency = new Vector<Vector<Integer>> ();

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Unchecked or Unsafe Operations

    And why not use List and ArrayList as Vector is old and slow and if you need thread safety you can use Collections.synchronizedList.

    // Json

Similar Threads

  1. Help With Java Homework: Set Operations
    By kilroyjr in forum Java Theory & Questions
    Replies: 10
    Last Post: April 1st, 2011, 09:41 AM
  2. Help with OS operations!
    By benglish in forum Java Theory & Questions
    Replies: 8
    Last Post: April 1st, 2011, 06:32 AM
  3. Operations with lists
    By datreta in forum Collections and Generics
    Replies: 8
    Last Post: October 29th, 2010, 08:54 AM
  4. unsafe operations note??
    By bookface in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 22nd, 2010, 09:58 AM
  5. Bulk operations on sets/ map problem
    By kyuss in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 14th, 2010, 12:48 PM