The following types do not represent a collection of values, nor do they appear explicitly in the program. They are only introduced with the internal type of the defined identifier.
Method type
The method type is internally represented as(Ts) U,(Ts)is a type sequence(T1,..., TN) n>=0,Uis a(Value or method)type. This type represents a named method whose type of argument isT1,..., TN, the type of the returned result isU.
The method type is right-associative,(Ts1) (Ts2) Uthe way to be handled is(Ts1) ((Ts2) U).
A special case is a method type that has no parameters. Can be written in the form of a =>t. The parameterless method name expression will be evaluated each time the name is referenced.
The method type does not exist in the form of a value type. If the method name is referenced as a value, its type is automatically converted to the corresponding function type (§6.25).
Example 3.3.1 The following statement:
def A:int
def B (x:int): Boolean
def C (X:int) (y:string, z:string): String
The following types are produced:
A: = = Int
B: (Int) Boolean
C: (Int) (String, String) string
Polymorphic Method Types
Polymorphic method types are internally represented as[Tps]t,[TPS]is the type parameter section[A1: L1<: U1,..., aN: LN<: UN],n>=0,Tis a(Value or method)type. The type represents aS1,..., SNis a type parameter and produces a type ofTThe result of the named method, the parameter typeS1,..., SNand The NetherL1,..., LNand Upper boundsU1,..., UNconsistent(§3.2.4).
Example 3.3.2 The following statement:
def Empty[a]: list[a]
def union[a <: Comparable[a] [x:set[a], Xs:set[a]): Set[a]
The following types are generated:
Empty: [A;: Nothing <:] List[a]
Union: [A;: Nothing <: Comparable[a]] (X:set[a], xs:set[a]) Set[a]
Type constructor
The inner representation of a type constructor is similar to a polymorphic method type. [+/-a1: L1<: U1,..., +/-aN: LN<: UN] Trepresents a type constructor parameter that is expected to be(§4.4)or an abstract type constructor binding that has a corresponding type parameter clause(§4.3)of the type.
Example 3.3.3 the following are class Iterable[+x] Fragments of:
Trait Iterable[+x] {
def flatmap[newtype[+x]<:iterabe[x], S] (f:x = Newtype[s]): Newtype[s]
}
Conceptually, the type constructor iterable is anonymous type [+x] iterable[x] the name, in
FlatMap passed to the NewType The type constructor parameter.
Scala non-value types in a detailed