0

I'm newer working on a trait then I found this syntax that I didn't understand

trait Holder[H <: service.SealedHolder[H]] {
    val personId: String //ID.03
}

I guess that may be a generic declaration but still confused about this scala syntax Holder[H <: service.SealedHolder[H]]

Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
e2rabi
  • 4,728
  • 9
  • 42
  • 69

1 Answers1

3

You're right, it's a generic declaration that H is a subtype of SealedHolder[H].

You can read about type bounds https://apiumhub.com/tech-blog-barcelona/scala-type-bounds/ and F-bounded polymorphism https://tpolecat.github.io/2015/04/29/f-bounds.html

For example F-bounds are used with trait Ordered https://www.scala-lang.org/api/2.12.2/scala/math/Ordered.html

case class OrderedClass(n:Int) extends Ordered[OrderedClass] {
  def compare(that: OrderedClass) = this.n - that.n
}
Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66