2

I am going through some scala code. I have come across a sign "<:". What does it mean?

Here is the following code.

abstract class HierarchicalDatabaseObject[TParent <: DatabaseObject](databaseId: String) extends DatabaseObject(databaseId)
odbhut.shei.chhele
  • 5,834
  • 16
  • 69
  • 109
  • 1
    It's upper type bound: http://www.scala-lang.org/old/node/136 – Łukasz Apr 12 '16 at 06:32
  • 2
    Possible duplicate of [Scala type parameter bounds](http://stackoverflow.com/questions/6713385/scala-type-parameter-bounds) – Ven Apr 12 '16 at 06:34
  • Possible duplicate of [What do all of Scala's symbolic operators mean?](http://stackoverflow.com/questions/7888944/what-do-all-of-scalas-symbolic-operators-mean) – Chris Martin Apr 12 '16 at 07:02

1 Answers1

3

It's a upper bounded wildcard. If you're familiar with Java it's like ? extends DatabaseObject.

It means, that the Type you put in has to be a Subtype of DatabaseObject. This basically guarantees, that your generic Type has atleast all the same methods and properties that DatabaseObject has, making it much more useful, than when unbound.

You can check out more examples in the documentation.

Luka Jacobowitz
  • 22,795
  • 5
  • 39
  • 57