I am having trouble with unchecked casting. I know this happens because T
is an Object
but not every Object
is a T
. My question is how would I fix this to implement T
in ArrayList<T>
without suppressing warnings?
public class AdjMatrix <T extends Object> implements Blah<T>
{
public T[] vertex;
public AdjMatrix()
{
this.vertex = (T[])(new Object[RANDOM_NUMBER]);
}
public ArrayList<T> neighbours(T vertLabel)
{
ArrayList<T> neighbours = new ArrayList<T>();
neighbours.add(vertex[SOME_NUMBER]);
return neighbours;
}
}
Thanks for you help!