6

specs2 には、Around と呼ばれるメソッドがあり、ここに文書化されており、次の例があります。

object http extends Around {
  def around[T <% Result](t: =>T) = openHttpSession("test") {
    t  // execute t inside a http session
  }
}

このコードのソースはここにあります。

このコンテキストで <% 演算子が何を意味するのか興味がありますか?

編集:これは、この主題に関する確固たる答えです。Scalaコンテキストとビューの境界は何ですか?

4

1 に答える 1

5

This is a view bound. It means, that the type T must be convertible to the type Result. For more information about type bounds I recommend you http://www.cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/scala/ProgrammingInScala.pdf, starting at page 61.

于 2012-07-17T06:15:28.633 に答える