Java Generic Primitive type n-d array -


i have pass primitive 2d array filtering routine.the algorithm filtering(median filter) same irrespective of type of array.is there way pass type of array in generic manner or should overload same same function different array types.in second case same code have repeated different data types.

int[][] medianfilter(int[][] arr){ ... } float[][] medianfilter(float[][] arr){ ... } 

is there way make above code generic one,instead of repeating code medianfilter in each every overloaded function ?

there no way primitive arrays, why library functions (such java.util.arrays) have these duplicated methods.

you define method

object[] medianfilter(object[] arr); // note missing dimension 

and use reflection find out runtime type. system.arraycopy doing. need type-cast. ugly.

int[][]  result = (int[][]) medianfilter( input ); 

go duplicated methods.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -