Skip to content

Instantly share code, notes, and snippets.

@yoshiori
Created March 28, 2012 06:12
Show Gist options
  • Save yoshiori/2224153 to your computer and use it in GitHub Desktop.
Save yoshiori/2224153 to your computer and use it in GitHub Desktop.
括弧省略
object Main {
def main(args: Array[String]){
Main puts "Main"
this puts "this"
// puts "foo" これがダメなのなんで???
}
def puts(text:String){
println(text)
}
}
@kmizu
Copy link

kmizu commented Mar 28, 2012

  • Main puts "Main" や this puts "this" での、putsは中置演算子としてみなされます(Scalaでは、任意の識別子を中置演算子として使えます)。一方、
    puts "foo" の、putsは、中置演算子でない(obj op param形式に従っていない)ので、演算子とみなされません。Scalaでは、レシーバが無いメソッド呼び出しで引数が一つ以上ある場合、括弧が省略できないので、puts "foo"は無理ということになります。

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