How do I Implement Operators in a Java Class

后端 未结 7 1817
南旧
南旧 2020-12-07 01:30

I am attempting to create a unsigned integer class.

public class UnsignedInteger extends Number implements Comparable 
    { 
    ...          


        
相关标签:
7条回答
  • There is a javac-plugin (an annotation processor like Lombok) called "Java-OO", which adds operator overloading to Java.

    It allows you to add operator overloading to your own classes very easily. In addition to this, many of the built-in classes of the Java API also supports operator overloading when using this plugin. (For example: Instead of list.get(6) or map.get("hello") you can do list[6] and map["hello"])

    All you need to do is to include the .jar on the classpath when compiling with javac.

    There are plugins for all major IDEs: Eclipse, Netbeans and IntelliJ IDEA.

    0 讨论(0)
提交回复
热议问题