I've this function;
public static T[] addToArray(T item, T... items){
T[] array;
int array_size = 1;
if(items !=null){ array_size = items.length+1; }
array = java.util.Arrays.copyOf(items, array_size);
array[array_size-1] = item;
return array;
}
And I get this error cannot find symbol symbol: class T
. The idea is to make this method generic. I never worked with generics so I'm guessing I miss some reference?
Method signature for generic method is as follows
public static <T> T[] addToArray(T item, T... items){
T[] array;
int array_size = 1;
if(items !=null){ array_size = items.length+1; }
array = java.util.Arrays.copyOf(items, array_size);
array[array_size-1] = item;
return array;
}
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