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
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With