问题描述
在specs2中,有一种名为Around的方法,在此处记录的具有以下示例:
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?
编辑:这是关于此主题的可靠答案,
here is a solid answer on this subject, What are Scala context and view bounds?
推荐答案
这是一个视图绑定.这意味着 T
类型必须可转换为 Result
类型.有关类型边界的更多信息,我建议您 http://www.cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/scala/ProgrammingInScala.pdf ,从第61页开始.
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.
这篇关于<%运算符在Scala泛型中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!