public static <T> void func1(T[][] arr) {
...
}
public static <T> void func2(T[] arr) {
...
}
I'm trying to pass a 2-dimensional array, int[][] arr
.
I cannot use func1(arr)
, but I can use func2(arr)
Can someone explain me how this works?
T[]
represents an array of some generic object. Any array type (including int[]
) is an object. Therefore, int[][]
is a valid T[]
when T = int[]
.
However, because int
is not an object, int[][]
is not a valid T[][]
.
If you you use Integer
instead of int
, you should be able to:
func1
with Integer[][] arr
func2
with Integer[] arr
or Integer[][] arr
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