I have a homework task where I am required to write only 1 method (a member of class MainClass) which creates simultaneously more than one type of array -with only using this method. I tried to create a method that returns the corresponing type but then it can only be done with one type of array (see the commented code /function/). My question is how can I create sort of a templated function which returns all types at once my attemp is below, /but sadly not working/?
import java.lang.reflect.Array;
import java.sql.SQLOutput;
import java.util.Arrays;
public class MainClass {
//ще направим отделни методи за класовете
/*public int [] returnArr(){
int [] ar = new int[10];
return ar;
}*/
public void createArray(){
//here I create more than one type of array:
int []ar = new int[10];
String[] str = new String[10];
double [] dbl = new double[10];
}
}
class Test{
public static void main(String[] args) {
MainClass mcl = new MainClass();
/*int [] ia = mcl.returnArr();
for (int i = 0;i<10;i++){
Arrays.fill(ia,0,9,8);
}*/
mcl.createArray();
//here the ar[] array is not accessible
Arrays.fill(ar,0,9,0);
for (int i:ar){
System.out.println(i);
}
}
}