What does the <% operator mean in Scala generics? [duplicate]

故事扮演 提交于 2021-01-21 08:24:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!