I want to do something like this: int a=4 plus 5;
Here plus
is userdefined operator that is defined by me may in jvm level. Is it possible to do something like that
I want to do something like this: int a=4 plus 5;
Here plus
is userdefined operator that is defined by me may in jvm level. Is it possible to do something like that
No, there is no way to define infix operators or overload existing operator symbols in the Java language.
You can however use a language which suppots this, if it compiles to the JVM (bytecode).
It is one of the reasons why alternative JVM languages like JRuby, Groovy or Scala are used, especially if you want to form a internal DSL. They all have more freedoms in this area (to a varying degree).
And if you don't want to compile to Java you can also use the built-in script interpreter framework and use a more flexible scripting language supported. (for example you can extend Jasper Reports with Groovy).