3 Replies Latest reply: Feb 5, 2010 6:32 PM by 843810

# warning: [unchecked] unchecked cast found

warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.Vector<java.lang.Long>
copy.path = (Vector<Long>) this.path.clone();
1 warning

Here is the code

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cs572project1;

import java.util.*;
/*
* Richard Becraft
* 1/22/2010
* CS 572 Heuristic Problem Solving
*
* This class represents a node in a search tree of a graph that represents a street map.
*/

public class SearchNode implements Cloneable {

public long depth;
public double costSoFar;
public double estimatedCostToGoal;
public Vector<Long> path;

public SearchNode() {
depth = -1;
costSoFar = -1;
estimatedCostToGoal = -1;
path = new Vector<Long>(20, 20);
}

public void printSearchNode() {
System.out.println("\n****In printSearchNode");
System.out.println("depth: " + depth + " costSoFar: " + costSoFar + " estimatedCostToGoal: " + estimatedCostToGoal);
for (Enumeration<Long> e = this.path.elements(); e.hasMoreElements();) {
System.out.println(e.nextElement());
}
System.out.println("****Exiting printSearchNode\n");
}

@Override
public SearchNode clone() {
SearchNode copy;
try {
//System.out.println("in clone SearchNode");
copy = (SearchNode) super.clone();
copy.path = (Vector<Long>) this.path.clone(); // <<<< the offending line
//copy.path = new Vector<Long>(this.path.capacity());
//this.printSearchNode();
//System.out.println("copy.path.size: " + copy.path.size());
//System.out.println("this.path.size: " + this.path.size());
//System.out.println("copy.path.capacity: " + copy.path.capacity());
//System.out.println("this.path.capacity: " + this.path.capacity());
//Collections.copy(copy.path, this.path);
} catch (CloneNotSupportedException e) {
throw new RuntimeException("This class does not implement Cloneable " + e);
}
return copy;
}
}
• ###### 1. Re: warning: [unchecked] unchecked cast found
Use code tags when you post code. There is a generics forum where this question would be better posted.
• ###### 2. Re: warning: [unchecked] unchecked cast found
rickbecraft wrote: