the first part of my project is to construct an hypergraph
This is a quickly-drew UML diagram
The vertex class
public abstract class Vertex <T>{
int vertexId ;
T vertexValue ;
public abstract <T> T setVertexValue();
}
The imageVertex class
public class ImageVertex extends Vertex<Map<String, Instance>>{
@Override
public <T> T setVertexValue() {
// TODO Auto-generated method stub
return null;
}}
I has thought that Type will be inferred automatically as i define it for the imageVertex Map and later for tagVertex as String
had I wrongly used the generics?
You've redefined the type T on setVertexValue
. Use this.
public abstract class Vertex <T>{
int vertexId ;
T vertexValue ;
public abstract T setVertexValue();
}
It uses the generic properly
public class ImageVertex extends Vertex<Map<String, String>>
{
@Override
public Map<String, String> setVertexValue()
{
// TODO Auto-generated method stub
return null;
}
}
It seems that you are trying to write:
public abstract class Vertex<T> {
int vertexId;
T vertexValue;
public abstract T setVertexValue(); // NOTE: no <T>
}
public class ImageVertex extends Vertex<Map<String, Instance>> {
@Override
public Map<String, Instance> setVertexValue() {
return null;
}
}
In your code, the <T>
in
public abstract <T> T setVertexValue();
is a completely separate generic parameter that shadows the T
in Vertex<T>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With