0
1

More than 5 years have passed since last update.

a == 1 && a == 2 && a == 3がtrueになるGroovyスクリプト

Last updated at Posted at 2018-01-24

いま流行の(a == 1 && a == 2 && a == 3)をtrueにできるかをGroovyでやってみます。

Groovyは演算子オーバーロードが使えるので
==を上書きすれば良いのですが今回は別のアプローチを

class Hoge {
    def a = 1
    def getA() { this.a++ }
}

new Hoge().with {
    if (a == 1 && a == 2 && a == 3) {
        println 'true'
    } else {
        println 'false'
    }
}

withを使うことでGetterをシンプルに呼びだしています。

まとめ

元ネタに同じ解法があるので何番煎じかわかりませんが、
とりあえずブームの波に乗ってみました。

0
1
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
1