问题
In specs2 there is a method called Around, documented here that has the following example:
object http extends Around {
def around[T <% Result](t: =>T) = openHttpSession("test") {
t // execute t inside a http session
}
}
The source for this code can be found here.
I'm curious what the <% operator means in this context?
EDIT: here is a solid answer on this subject, What are Scala context and view bounds?
回答1:
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.
来源:https://stackoverflow.com/questions/11515940/what-does-the-operator-mean-in-scala-generics