0

in the method definition below

def fixed[A: Read : Write](start: Int, end: Int, align: Alignment = Alignment.Left,
                             padding: Char = ' ', defaultValue: A = null.asInstanceOf[A]): Codec[A]

what does [A: Read : Write] mean

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
  • 1
    I would be more worried about having `null` as a default value for an argument... – Tim Aug 19 '19 at 10:54

1 Answers1

0

This is called Context Bound introduced in Scala 2.8, which is a shorthand for providing implicit arguments. In your case, it means that, Read[A] and Write[A] values are implicitly provided.

Traditionally, you may provide implicit arguments for Read and Write for type A as:

def fixed[A](some params...)(implicit read: Read[A], write: Write[A]) = ???

But, same can be done using context bound as below. However, you have to use implicitly in order to access implicit value:

def fixed[A : Read : Write](some params...) = {
    val read = implicitly[Read[A]]
    val write = implicitly[Write[A]]
    ...
}
Ra Ka
  • 2,995
  • 3
  • 23
  • 31