I want to write a Java function that will get as input either int[], float[] or double[]. The algorithm is exactly the same (some kind of a scalar product). How can I write a single function that will be able to handle all types of numeric arrays?
I want to write a Java function that will get as input either int[]
Share
You can write one method to do them all, however, it won’t be anywhere near as readable of efficient. You have to make a choice between what is a generic or an efficient solution.
prints
If you are only working on relatively small arrays, the generic but less efficient solution may be fast enough.