This may be possible with Generics.
I do not know about that. I recommend that you read about this in the documentation. http://docs.oracle.com/javase/tutorial/java/generics/index.html
Generics works with objects, so I think you cannot pass String [] and int [] in the same method. Use Integer [] instead.
Here is the code I would use:
public static <K> int length(K[] array){ return array.length; }
It may also work:
public static int length(Object[] array){ return array.length; }
But this will not allow you to use a specific type of object instead of the Object class.
I am completely new at this, perhaps there is a better solution, but this is the only thing I know!
source share