Java Operator Overloading Plugin
Originally JOPS stood for "Java Opcodes", but that didn't make sense anymore, so now it stands for Java Operator Overloading Plugin.
I know I know, it should be called JOOP instead, but I like JOPS better. Oh yeah, the 'S' stands for Syntactic Sugar Edition.
- add @OperatorOverloading annotation to the class with overloaded operators
- overload the operators with the following C++ syntax:
@OperatorOverloading
public class Bla {
public Bla operator+(Bla b) {
return ...//something..or nothing
}
}
- ...
- write some code, and behold:
public class BlaTest {
public static void main(String[]args) {
Bla a = new Bla();
Bla b = new Bla();
Bla c = a + b;
System.out.println("operator overloading banzai!");
}
}
operator+
operator-
operator*
operator/
operator+=
operator-=
operator*=
operator/=
- include the jops_plugin as a dependency(we need this for the @OperatorOverloading annotation)
<dependencies>
<dependency>
<groupId>io.github.blackbeard334</groupId>
<artifactId>jops_plugin</artifactId>
<version>${jops_plugin.version}</version>
</dependency>
</dependencies>
- next you need to add the jops_plugin as a compiler arg, and as a dependency for the maven-compiler_plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArgs>
<arg>-Xplugin:JOPSPlugin</arg>
</compilerArgs>
</configuration>
<dependencies>
<dependency>
<groupId>io.github.blackbeard334</groupId>
<artifactId>jops_plugin</artifactId>
<version>${jops_plugin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
javac -cp /path/jops -Xplugin:JOPSPlugin HelloWorld.java
- first we need to include the jops_plugin in the classpath
-cp /path/jops
- then we tell the compiler that we want to use the jops_plugin with the
-Xplugin:JOPSPlugin
switch - enjoy...
- first we need to include the jops_plugin in the classpath