I am trying to create a generic class in which the generic type itself can have methods.
This is what I did in Java:
public class DepthFirstPaths <GraphType> implements PathInterface
{
private final int start;
public DepthFirstPaths (GraphType G, int s)
{
int vCount = G.numVertex(); //This line is giving errors
start = s;
DFS(G, s);
}
//Other methods
....
}
GraphType can refer to a directed graph type or undirected graph type and this is because DFS does the same thing for both types of graphs given a source vertex. But the above java code gives errors like:
Description: The method numVertex() is undefined for the type GraphType
Resource: DepthFirstPaths.java
Path: /Paths/src/GraphAlgorithms
Location: line 17
Type: Java Problem
Plus other errors relating to using GraphType object methods in the code
What can I do to fix this? What is the best way to do this?