1. Member Join Date
Apr 2011
Posts
7
Rep Power
0

## unchecked conversion found

Doing a school assignment and cant figure out how the get rid of 2 unchecked conversions.
Everything works as it should but i figured id sort this before handing the assignment in.
Java Code:
```	private static<E> void depthFirstSearch(Graph graph, E e, Set<E> visited){
Map<E, List<ListEdge<E>>> nodes = graph.getNodes();
for(ListEdge<E> le : nodes.get(e)){
if(!visited.contains(le.getDest())){
depthFirstSearch(graph, le.getDest(), visited);
}
}
}```
Java Code:
```	public static<E extends Comparable<? super E>> List<ListEdge<E>> shortestPath(Graph graph, E from, E to){
if(pathExists(graph, from, to)){
if(from.compareTo(to)==0)
return null;
Map<E, List<ListEdge<E>>> nodes = graph.getNodes();```
the second method is very long so only took the first part of it.
All the extends and supers are attempts to sort it.
If it matter the class is decalred like this:
Java Code:
`public class GraphMethods<E extends Comparable<? super E>>{`
And the method that is causing all the troubles:
Java Code:
```	public Map<E,List<ListEdge<E>>> getNodes(){
Map<E,List<ListEdge<E>>> temp = nodes;
return temp;
}```
Java Code:
```public class ListGraph<E extends Comparable<? super E>> implements Graph<E>{
private Map<E,List<ListEdge<E>>> nodes = new TreeMap<E, List<ListEdge<E>>>();```
both warnings are "unchecked conversion found" and points to getNodes() in the first 2 code examples  Reply With Quote

2. ## What are the definitions of the getNodes() method and the Graph class?  Reply With Quote

3. Member Join Date
Apr 2011
Posts
7
Rep Power
0

## Graph is just a interface declared like:
Java Code:
`public interface Graph<E extends Comparable<? super E>>`
i posted the entire getNodes() method in my earlier post. It basically just returns a copy of the whole data structure which is just a TreeMap.
Java Code:
`private Map<E,List<ListEdge<E>>> nodes = new TreeMap<E, List<ListEdge<E>>>();`
in my desperation i tried something like this:
Java Code:
```Object obj = graph.getNodes();
Map<E, List<ListEdge<E>>> nodes = (Map<E, List<ListEdge<E>>>)obj;```
but that ofc just left me with a unchecked cast warning.  Reply With Quote

4. ## Can you make a complete program that demonstrates the problem. Something that compiles and that could be worked on.  Reply With Quote

5. Member Join Date
Apr 2011
Posts
7
Rep Power
0

## well thanks for trying but a friend explained it to me and it was, as usual, very simple and as ive tried about a dozen different things i had actually almost sorted it before how to sort it:
Java Code:
`public static<E extends Comparable<? super E>> List<ListEdge<E>> shortestPath(Graph<E> graph, E from, E to){`
as opposed to the old one that gave a warning:
Java Code:
`public static<E extends Comparable<? super E>> List<ListEdge<E>> shortestPath(Graph graph, E from, E to){`
and if you cant spot it its the Graph<E> graph instead of just Graph graph. Silly little thing but ive found that its the silly little thing that takes most of my time  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•