Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of >: Null <: in Scala?

Tags:

scala

I searched a lot, but I didn't find anything, What is the meaning of this type of type declaration in Scala?

type Ident >: Null <: AnyRef
like image 463
Pooya Avatar asked Aug 05 '13 09:08

Pooya


1 Answers

Keyword type is for type alias declaration, just like val and def are for value and method declaration. In this case it's an abstract type alias with constraints, so it's a type member of some trait or class - type alias in local scope can't be abstract and can't have constraints.

Type Ident is a subtype of AnyRef and supertype of Null.

AnyRef

AnyRef is an ancestor of all reference types, all types except Int, Long, Char and so on (Java primitives).

Null

Null is subtype of all "nullable" types. In fact it's a subtype of all reference types.

Since all AnyRef are nullable the only additional constraint from >: Null is that Ident is not Nothing.

See Scala’s type hierarchy:

Scala’s type hierarchy

like image 65
senia Avatar answered Oct 17 '22 20:10

senia