odbhut.shei.chhele
odbhut.shei.chhele

Reputation: 6264

What does this sign "<:" mean in scala?

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)

Upvotes: 2

Views: 120

Answers (1)

Luka Jacobowitz
Luka Jacobowitz

Reputation: 23532

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.

Upvotes: 3

Related Questions