Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specializing a java class for both double and float precision [closed]

I was wondering could anyone help me with providing options for both double and float precision for a class please?

I am working with Java3D and from the API specification for Point3d and Point3f, it is my understanding that the implementation effectively duplicates the Point3f class replacing float with double where necessary. Is this because Generics cannot be used with primitive data types? Efficiency?

I am writing a Curve class and am wondering should I provide Curved and Curvef in a similar fashion. Is this the best option?

like image 730
felice Avatar asked Feb 28 '13 17:02

felice


1 Answers

Yes, unfortunately Java generics doesn't work on primitive types.

You could do code generation though, producing multiple java files from one template.

Java 8 is going to introduce a lot of specialized primitive versions of functional interfaces, like IntFunction. It's going to be quite ugly.

like image 105
irreputable Avatar answered Oct 03 '22 08:10

irreputable