Results 1 to 5 of 5
Thread: unchecked conversion found
- 08-12-2011, 03:24 AM #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){ visited.add(e); 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();
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>>{
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>>>();
- 08-12-2011, 03:28 AM #2
What are the definitions of the getNodes() method and the Graph class?
- 08-12-2011, 01:24 PM #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>>
Java Code:private Map<E,List<ListEdge<E>>> nodes = new TreeMap<E, List<ListEdge<E>>>();
Java Code:Object obj = graph.getNodes(); Map<E, List<ListEdge<E>>> nodes = (Map<E, List<ListEdge<E>>>)obj;
- 08-12-2011, 04:40 PM #4
Can you make a complete program that demonstrates the problem. Something that compiles and that could be worked on.
- 08-14-2011, 04:05 AM #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){
Java Code:public static<E extends Comparable<? super E>> List<ListEdge<E>> shortestPath(Graph graph, E from, E to){
Similar Threads
-
How to get rid of the unchecked or unsafe operations warning?
By yma16 in forum New To JavaReplies: 9Last Post: 05-11-2011, 05:31 PM -
Compile error - unchecked
By pahiker in forum New To JavaReplies: 18Last Post: 06-24-2010, 10:27 AM -
unchecked exceptions
By veens4444 in forum New To JavaReplies: 1Last Post: 06-08-2010, 07:36 AM -
Uses unchecked or unsafe operations message
By Robbinz in forum New To JavaReplies: 2Last Post: 12-06-2007, 11:56 PM -
UnChecked Exception
By Java Tip in forum Java TipReplies: 0Last Post: 11-18-2007, 08:06 PM
Bookmarks