-1

I have made a class in Java which I would like to add, subtract, multiply and divide with integers. I know that I could make methods in that class such as add(int a), divide(int a) etc. and then return what I want, but then if I wanted to actually divide them, I would have to do this:

int a = 5;
myClass b = myClass.divide(a); //I have a divide method in that class which returns another instance of the same class

instead of just saying

int a = 5;
myClass b = myClass / a

I was wondering if there was any specific way to do it so I would be able to use it as shown in the latter example.

Bobobot
  • 65
  • 1
  • 8

1 Answers1

1

Not possible using vanilla Java. It's possible with a compiler plugin, though.

https://github.com/amelentev/java-oo

dcow
  • 7,765
  • 3
  • 45
  • 65