1
1

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.

scala syntactic sugar?

Posted at

全部同じ行動をします。

def sample:Action[AnyContent] = {
  val result = Ok("Hello")
  val action = Action(result)
  return action
}
def sample1:Action[AnyContent] = {
  val action = Action(Ok("Hello"))
  return action
}

アクションを直接生成

def sample2:Action[AnyContent] = {
  return Action(Ok("Hello"))
}

scalaはreturnかかなくていい

def sample3:Action[AnyContent] = {
  Action(Ok("Hello"))
}

scalaは戻り値を型推論する

def sample4 = {
  Action(Ok("Hello"))
}

scalaはメソッドが1行ならカッコもいらない

def sample5 = Action(Ok("Hello"))

scalaは引数のカッコを中括弧にできる

def sample6 = Action{Ok("Hello")}

中括弧の中身は複数行かける

def sample7 = Action{
  Ok("Hello")
}
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?