In stock trading, quantities are usually integers (e.g. 5x shares, 10x options, etc). With cryptocurrencies, quantities are fractions (e.g. 0.01 bitcoin). In both scenarios, there is typically a minimum unit (e.g. multiples of 100x shares).
I would like to wrap this logic in a Quantity
class. However:
- Java native types (e.g.
double
) arefinal
, so I cannot extend them - Java does not support operator overloading, so arithmetic will be ugly
- Java does not support typedefs, so I cannot wrap a
double
with aQuantity
type
So I guess my question is this, if I want to create something akin to a native type (lots of instances, pass-by-value, lots of arithmetic), is there a "classic" Java solution? From memory, C# has a struct
type which is pass-by-value, is there something similar in Java?
Thank you,
EDIT: Is it possible to import a native type from C++ code, and effectively bypass Java?