I want to开发者_开发技巧 compare two MyDouble
values with zero.
if(getA()>(MyDouble.zero)) //where getA() is MyDouble
But it does not let me do that. Does anyone knows how to solve it?
You have to write a Comparator<MyDouble>
that does the job. You'll implement the Comparator interface.
You won't be able to use the '>' comparison symbols to do it. You'll do something like this:
x.compareTo(y)
You should implement duffmo's solution as this is what Double and all Numbers do. Another way to solve this is to access the fields directly or provide a specific method to do the comparison. (This could be more efficient than implementing compareTo)
if(getA().value > MyDouble.ZERO.value) // Constants are in UPPER_CASE
or
if(getA().greaterThan(MyDouble.ZERO))
精彩评论