generics - Changing the type of primitive arrays in Java -


i have numeric program in java lot of operations on primitive arrays. use primitive arrays (double[]/float[]/int[]) because more memory , time-efficient dealing arrays of pointers values (e.g. arraylist<float>).

now, want able change primitive type, eg. double float, based on parameter program. since primitive can not used generics, can't life of me figure out how.

is there way, or vast amount of code replication or casting have unavoidable flaw of java?

do need deal primitive types only? if not, consider having array of number - way can instantiate either float[] or double[].

number numbers[] = (param == "float" ? new float[n] : new double[n]); 

i assume using wrappers less efficient using primitives (i haven't benchmarked though) it's sure faster using collections (eg arraylist).


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -