Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

generics - Meaning of additional colon in Scala class parametrization

What does [A : Manifest : WireFormat] mean in the following code? It's from com.nicta.scoobi.TextInput (available on github). It doesn't seem to be any of the usual type bounds.

  def fromDelimitedTextFile[A : Manifest : WireFormat]
      (path: String, sep: String = "")
      (extractFn: PartialFunction[List[String], A])
    : DList[A] = {

    val lines = fromTextFile(path)
    lines.flatMap { line =>
      val fields = line.split(sep).toList
      if (extractFn.isDefinedAt(fields)) List(extractFn(fields)) else Nil
    }
  }

Where can I find more information about this topic?

question from:https://stackoverflow.com/questions/12786910/meaning-of-additional-colon-in-scala-class-parametrization

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is called a context bound. They are syntactic sugar for an implicit parameter list:

def meth[A : ContextBound1 : ContextBoundN](a: A)

// ==>

def meth[A](a: A)(implicit evidence: ContextBound1[A], ContextBoundN[A])

If there are multiple context bounds from 1 to N, they are all translated into the same parameter list. See this question for a more detailed explanation about how they work and for what they are useful.

To find such symbols it is useful to read the StackOverflow Scala Tutorial.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...