Operator overloading and overriding in Java

后端 未结 5 1422
醉酒成梦
醉酒成梦 2020-11-29 13:25

What is the difference between operator overloading and operator overriding?

Are they the same in inheritance and console program?

5条回答
  •  攒了一身酷
    2020-11-29 13:55

    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.

提交回复
热议问题