I am having issues in implementing the Generic DirectGraph Implementation. Please help me!
public interface DirectedGraph<Vertex<T extends Comparable<T>>> {
<T extends Comparable<T>> boolean addVertex(Vertex<T> v);
<T extends Comparable<T>> boolean addEdge(Vertex<T> v1, Vertex<T> v2);
int size();
<T extends Comparable<T>>boolean removeEdge(Vertex<T> v1, Vertex<T> v2);
<T extends Comparable<T>>boolean hasEdge(Vertex<T> v1, Vertex<T> v2);
}
public class Vertex<E extends Comparable<E>> {
E vertex;
}
What is wrong with the above code?. Eclipse is showing the error
Multiple markers at this line
- Syntax error on token "<", , expected
- The type parameter Vertex is hiding the type
Vertex<E>
- Syntax error on token ">>>", >> expected
Either you make a class generic or a method generic.In your case,you are doing both.Also,since you have decided that DirectedGraph
will use Vertex
type,it is not the class Vertex but type "Vertex" .You use a concrete class or interface type when you use the class or generic method and not in the definiton itself
public interface DirectedGraph<T extends Comparable<T>> {
boolean addVertex(Vertex<T> v);
boolean addEdge(Vertex<T> v1, Vertex<T> v2);
int size();
boolean removeEdge(Vertex<T> v1, Vertex<T> v2);
boolean hasEdge(Vertex<T> v1, Vertex<T> v2);
}
class Vertex<E extends Comparable<E>> {
E vertex;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.