Skip to content

Instantly share code, notes, and snippets.

@ezura
Created June 17, 2017 07:22
Show Gist options
  • Select an option

  • Save ezura/ab2cfee3de41410db840000775ec928b to your computer and use it in GitHub Desktop.

Select an option

Save ezura/ab2cfee3de41410db840000775ec928b to your computer and use it in GitHub Desktop.
operator のメソッド感
class A() {
operator fun plus(that: Int): Int {
return that + 1
}
}
A() + 1
// error
// 1 + A()
/* インスタンスと密着してる感じがする。演算子もメソッドの雰囲気 */
@ezura
Copy link
Copy Markdown
Author

ezura commented Jun 17, 2017

swift では

class A {
    static func +(l: A, r: A) -> A {
        return l
    }
}

関数関数してる

@ezura
Copy link
Copy Markdown
Author

ezura commented Jun 17, 2017

kotlin はオブジェクト指向だなぁって思った

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment