Take the 2-minute tour ×

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.

share|improve this question
You can't call operators reflectively. –  Strelok Sep 27 '10 at 7:40
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer


