views:

39

answers:

2

I would like to be able to retrieve the available operators for an object at runtime, possibly in a similar way as the getMethod() call.

In particular, I need to be able to call the less-than/greater-than operators of an object at runtime.

Basically, I have a bunch of primitives that have been cast to the Object object-type. I need to perform comparisons between them at run-time. (I do know that the objects being compared will be of the same original type, and have implemented my own type-checking).

Alternatively.. Maybe there is a way to programatically cast these objects back to their original type, and use their native comparison operators.. somehow?

Thanks for any assistance.

+2  A: 

There is no way in Java to get available operators. For comparison the class should (you may do this thru reflection also) implement the Comparable interface.

PeterMmm
+1  A: 

If they are auto-boxed primitive types, the set of arithmetic operators is identical for all types other than Boolean, and the set of bitwise operators ditto apart from the two FP types.

EJP