I'm trying to use generics in some methods and Netbeans is telling me I'm doing it wrong. It tells me that the lines ***Data = input is wrong and return ***Data[index] with errors to the effect of,
required: byte[]
found: T[]
or
required: T
found: byte
Is there a way to make what I'm doing work or are generics simply not going to work here? I've tried wrapping the primitives in wrappers.
private byte[] byteData;
private short[] shortData;
private int[] intData;
private long[] longData;
private float[] floatData;
private double[] doubleData;
private int[] dimensions;
private int[] strides;
private int start, length;
private char type;
public <T extends Number> MyArrayOld(T[] input, int start, int[] dimensions, char type){
this(dimensions, type);
this.start = start;
switch(type){
case '1':
byteData = input;
break;
case 's':
shortData = input;
break;
case 'i':
intData = input;
break;
case 'l':
longData = input;
break;
case 'f':
case 'F':
floatData = input;
break;
case 'd':
case 'D':
doubleData = input;
break;
}
}
@Override
public <T extends Number> T get(int index) {
switch(type){
case '1':
return byteData[index];
case 's':
return shortData[index];
case 'i':
return intData[index];
case 'l':
return longData[index];
case 'f':
case 'F':
return floatData[index];
case 'd':
case 'D':
return doubleData[index];
}
}