0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Groovyでオーバーロード可能な演算子を優先順に

Last updated at Posted at 2019-11-03

すっきり表記したいから演算子をオーバーロードするのですが、優先順位を意識して設計しないと括弧だらけになってしまいます。

Usage Implementation
x() x.call()
x[y] x.getAt(y)
x++ x.next()
x-- x.previous()
~x x.bitwiseNegate()
公式ドキュメントにはbitwiseNegateが他と同レベルと書かれているのですが、実際に~x++を実行するとnextの後でした。
Usage Implementation
x**y x.power(y)
Usage Implementation
+x x.positive()
-x x.negative()
Usage Implementation
x*y x.multiply(y)
x/y x.div(y)
x%y x.mod(y)
Usage Implementation
x+y x.plus(y)
x-y x.minus(y)
Usage Implementation
x<<y x.leftShift(y)
x>>y x.rightShift(y)
x>>>y x.rightShiftUnsigned(y)
Usage Implementation
x in y y.isCase(x)
x as y x.asType(y)
Usage Implementation
x&y x.and(y)
Usage Implementation
x^y x.xor(y)
Usage Implementation
x|y x.or(y)
Usage Implementation
x[y] = z x.putAt(y, z)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?