I would like to be able to take in any array type as a parameter in a method.:
public void foo(Array[] array) {
System.out.println(array.length)
}
Use generics.
public void foo(T[] array) {
System.out.println(array.length);
}
This will not work for array of primitive types, such as int[]
, boolean[]
, double[]
,... You have to use their class wrappers instead: Integer[]
, Boolean[]
, Double[]
, ... or overload your method for each needed primitive type separately.