I have a whole bunch of classes that define these two constants, eg:
public class Face
{
public static final int LUMP_INDEX = 1;
public static final int SIZE = 20;
blah blah
}
public class Edge
{
public static final int LUMP_INDEX = 5;
public static final int SIZE = 32;
blah blah
}
etc.
At the moment, i have a function for each one to create an array of that class, using the 2 constants defined in the class.
private Face[] createFaces(RandomAccessFile in)
{
int numFaces = doSomeCalculations(Face.LUMP_INDEX, Face.SIZE);
Face[] faces = new Face[numPlanes];
blahblah;
for(int i = 0; i < numFaces; i++)
faces[i] = new Face();
return faces;
}
A bit silly to have a create function for every class. The only thing that changes is the class type. So i wanted to create a genertic method that would work with any of the classes above. Something like:
private T[] create(RandomAccessFile in, Class T)
{
int num = doSomeCalculations(T.LUMP_INDEX, T.SIZE);
T[] faces = new T[numPlanes];
blahblah;
for(int i = 0; i < num; i++)
faces[i] = new T();
return faces;
}
However I'm not sure how to do it properly. Any help would be appreciated. Thanks.
getmethods.Tfirst, then usingt.setNumPlaces(n). Or store configuration elsewhere, e.g.,UtilClass.getLumpIndex(Faces.class).