Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define a new operator in Groovy?

Is it possible to define a brand new operator in Groovy? I would like to express a trade where someone buys 200 items for the price of 10 like this:

def trade = 200 @ 10

Is this achievable?

Thanks

EDIT: I want to make it clearer that I am interested in defining an operator not adding a method. Cheers.

like image 735
Dalibor Novak Avatar asked Jun 26 '11 18:06

Dalibor Novak


1 Answers

We always wanted the ability to define an operator through the user in Groovy, but so far we haven't gotten around the problems that come along with that. So the current state is that Groovy does not support custom operators, only the ones that are already in use.

like image 139
blackdrag Avatar answered Oct 13 '22 12:10

blackdrag