开发者

How to compare two MyDouble values?

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))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜