Scala Unified Types Flashcards

1
Q

Any

Definition

A

Any is the supertype of all types, also called the top type. It defines certain universal methods such as equals, hashCode, and toString.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Any’s direct subsclasses

A

AnyVal and AnyRef

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

AnyVal

Definition

A

AnyVal represents value types

There are nine predefined value types and they are non-nullable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

List 9 predefined value types

A

Double, Float, Long, Int, Short, Byte, Char, Unit, and Boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

AnyRef

Definition

A

AnyRef represents reference types

All non-value types are defined as reference types. Every user-defined type in Scala is a subtype of AnyRef. If Scala is used in the context of a Java runtime environment, AnyRef corresponds to java.lang.Object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Type casting

How value types are casted in Scala

A
  • Byte -> Short -> Int -> Long -> Float -> Double
  • Char -> Int
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Nothing

Definition

A

Nothing is a subtype of all types, also called the bottom type.

There is no value that has type Nothing. A common use is to signal non-termination such as a thrown exception, program exit, or an infinite loop (i.e., it is the type of an expression which does not evaluate to a value, or a method that does not return normally).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Null

Definition

A

Null is a subtype of all reference types (i.e. any subtype of AnyRef). It has a single value identified by the keyword literal null.

Null is provided mostly for interoperability with other JVM languages and should almost never be used in Scala code. We’ll cover alternatives to null later in the tour.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly