A method declared by the ScalaObject
trait and used internally by Scala. It takes no arguments and returns an integer. It is currently used to optimize pattern matching, but it may be removed in a future release of Scala. While normally invisible to Scala code (it is generated automatically by the compiler), Java code that extends some Scala traits and classes may need to implement this method.
The outwardly visible state, state transformations, and other operations supported by a type. This is separate from the encapsulated implementation (fields and methods) of the abstraction. Scala traits and abstract classes are often used to define abstractions and optionally implement them. Concrete types provide complete implementations.
type
declaration within an class or trait that is abstract.
An autonomous sender and receiver of messages in the actor model of concurrency.
A concurrency model where autonomous actors coordinate work by exchanging messages. An actor’s messages are stored in a mailbox until the actor processes them.
Any type that has one or more @ annotations applied to it.
A way of attaching “metadata” to a declaration that can be exploited by the compiler and other tools for code generation, verification and validation, etc. In Scala (and Java) An annotation is a class. When used, it is prefixed with the @ character.
Any explicit type declarations are also called type annotations.
One or more additions to a type declaration that specify behaviors like variance under inheritance, bounds, and views.
In Scala, any object
with a main
routine that is invoked by the JVM or .NET CLR at the start of a new process.
The number of arguments to a function.
(Sometimes called Aspect-Oriented Software Development) An approach to cross-cutting concerns, where the concerns are designed and implemented in a “modular” way (that is, with appropriate encapsulation, lack of duplication, etc.), then integrated into all the relevant execution points in a succinct and robust way, e.g. through declarative or programmatic means. In AOP terms, the execution points are called join points, a particular set of them is called a pointcut and the new behavior that is executed before, after, or “around” a join point is called advice. AspectJ [AspectJ] is the best known AOP toolkit. Scala traits can be used to implement some aspect-like functionality.
A extension of Java that supports aspect-oriented programming. AspectJ supports two forms of syntax, an extended Java-based syntax and a “pure” Java syntax that uses Java annotations to indicate the pointcuts and advices of an aspect. The aspect behaviors (advices) can be incorporated into the target code at compile time, as a post-compile “weaving” step, or at load time.
Another name for a field, used by convention in many object-oriented programming languages. Scala follows Java’s convention of preferring the term field over attribute.
A secondary constructor of a class, declared as a method named this
with no return type. An auxiliary constructor must invoke the primary constructor or a previously defined auxiliary constructor as the first or only statement in its method body.
A synonym for parent type.
A style of test-driven development (TDD) that emphasizes TDD’s role in driving the understanding of requirements for the code. You follow the same process as in TDD, where the “tests” are written before the code. The difference is that the automated tests are written in a format that looks more like a requirements (or behavioral) specification and less like a test of the code’s conformance to the requirements. However, the specification format is still executable and it still provides the verification, validation and regression testing service that TDD tests provide.
A variable that is declared as an argument to a function literal. It is “bound” to a value when the closure created from the function literal is invoked.
A by-name parameter looks like a function value that takes no parameters, but rather than being declared with the signature p: () ⇒ R
, where
R
is the return type, it is declared with the signature p: ⇒ R
. By-name parameters are evaluated every time they are referenced in the function, rather than being evaluated once just before the function call, like a by-value parameter. For example, they are useful for a function that is designed to look like a control construct that takes a “block”, not a function with explicit parameter arguments, (think of how while loops look, for example). The function argument that has block-like behavior would be a by-name parameter.
A by-value parameter is the usually kind of method parameter that is evaluated before it is passed to the method. Contrast with by-name parameter.
See by-name parameter.
See by-value parameter.
See declaration site.
The keyword used in pattern matching expressions for testing an object against an extractor, type check, etc.
A class declared with the keyword case
. The Scala compiler automatically defines equals, hashCode and toString methods for the class and creates a companion object with an apply factory method and an unapply extractor method. Case classes are particularly convenient for use with pattern matching (case) expressions.
A class or trait that inherits from a parent class or trait. Sometimes called a subtype or derived type. See inheritance.
An informal term used throughout the book to indicate a section of software that uses another as an API, etc.
A template for instances that will have the same fields, representing state values, and the same methods. Scala classes support single inheritance and zero or more mixin traits. Contrast with type.
In Scala, an instance that has been created from a function literal with all the free variables referenced in the function literal bound to variables of the same name in the enclosing scope where the function literal was defined. In other words, the instance is “closed” in the sense that the free variables are bound. Because they are instances, closures are first-class values. They can be passed to other functions to customize their behavior. For example, List.foreach
takes a closure that is applied to each element in the list. See also bound variables and function literals.
Scala follows the same comment conventions as Java, C#, C++, etc. A // comment
goes to the end of a line, while a /* comment */
can cross line boundaries.
An class
declared with the same name as an object and defined in the same source file. See also companion object.
An object
declared with the same name as a class (called its companion class) and defined in the same source file. Companion objects are where methods and fields are defined that would be statics in Java classes, such as factory methods, apply
and unapply
for pattern matching, etc.
For our purposes, an aggregation of cohesive types that expose services through well-defined abstractions, while encapsulating implementation details and minimizing coupling to other components. (There is a wide-range of definitions for component in computer science and industry.)
The actual type of a declaration of the form T1 extends T2 with T3 with … TN { R }
, where R
is the refinement (body). Definitions in R
affect the type.
A class, trait, or object with all methods, fields, and types defined. Instances can be created from concrete types. Contrast with abstract types.
The protocol and requirements that exist between a module (e.g., class, trait, object, or even function or method) and clients of the module. More specifically, see design by contract.
A kind of language grammar for which each nonterminal can be specified as a production without reference to additional context information. That is, each nonterminal can appear by itself on the left-hand side of the production the specifies it.
In the context of the variance behavior of parameterized types under inheritance, if a parameter A
is contravariant in a parameterized type T[-A]
, then the -
is the variance annotation and a type T[B]
is a supertype of T[A]
if B
is a subtype of A
. See also covariance and invariance.
In the context of the variance behavior of parameterized types under inheritance, if a parameter A
is covariant in a parameterized type T[+A]
, then the +
is the variance annotation and a type T[B]
is a subtype of T[A]
if B
is a subtype of A
. See also contravariance and invariance.
“Concerns” (kinds of requirements, design or coding issues) that don’t fit in the same boundaries as the primary modularity decomposition. The same behaviors must be invoked consistently at specific execution points over a range of objects and functions. For example, the same ORM (Object-Relational Mapping) persistence strategy needs to be used consistently for a set of classes, not just a single class. Hence, such “concerns” are said to be “cross-cutting”. Supporting these concerns should not involve duplication of code, etc. See also Aspect-Oriented Programming.
Converting an N argument function into a sequence of N functions of one argument, where each function except for the last returns a new function that takes a single argument that returns a new function, etc., until the last function that takes a single argument and returns a value.
In reference to how the variance behavior of parameterized types is specified, in Scala, this is done when types are declared, i.e., at the declaration site. In Java, it is done when types are called (that is, used), i.e., at the call site.
The quality of many functional programs and Domain-Specific Languages where the code consists of statements that declare relationships between values and types, rather than directing the system to take a particular sequence of action. Contrast with imperative programming.
(Scala version 2.8) The ability to define a default value for a method argument that will be used if the caller does not specify a value. See also implicit argument and named argument.
A form of inversion of control, where an object’s external dependencies are given to it, either programmatically or through a DI framework that is driven by configuration information. Hence, the object remains “passive”, rather than taking an active role in resolving dependencies. The injection mechanism uses constructor arguments or field setters provided by the object. DI minimizes the coupling of objects. They only need to know about the abstractions of their dependencies.
A synonym for child type.
An approach to class and module design invented by Bertrand Meyer for the Eiffel language. For each entry point, valid inputs are specified in a programmatic way, so they can be validated during testing. These specifications are called preconditions. Similarly, assuming the preconditions are specified, specifications on the guaranteed results are called postconditions and are also specified in an executable way. Invariants can also be specified that should be true on entry and on exit.
A solution to a problem in a context. A code idiom or design structure that satisfies the needs of a frequently occurring problem, constraint, requirement, etc.
A custom programming language that resembles the terms, idioms, and expressions of a particular domain. An internal DSL is an idiomatic form of a general-purpose programming language. That is, no special-purpose parser is created for the language. Instead, DSL code is written in the general-purpose language and parsed just like any other code. An external DSL is a language with its own grammar and parser.
A term used in languages with dynamic typing for the way method resolution works. As long as an object accepts a method call (message send), the runtime is satisfied. “If it walks like a duck and talks like a duck, it’s a duck”. Contrast to the use of structural types in some statically-typed languages like Scala.
Loosely speaking, late binding of type information, sometimes referred to as binding to the value a reference is assigned to, rather than to the reference itself. Contrast with static typing.
Restricting the visibility of members of a type so they are not visible to clients of the type when they shouldn’t be. This is a way of exposing only the abstraction supported by the type, while hiding implementation details, which prevents unwanted access to them from clients and keeps the abstraction exposed by the type consistent and minimal.
The notification of a state change in event-based concurrency.
A high-performance form of concurrency where events are used to signal important state changes and handlers are used to respond to the events.
A way of expressing the presence of a type without knowing its concrete value, sometimes, because it can’t be known. It is used primarily to support aspects of Java’s type system within Scala’s type system, including type erasure, “raw” types (e.g., pre-Java 5 collections), and call site type variance.
An unapply
method defined in a companion object that is used to extract the constituent values for fields in an object. They are most commonly used in pattern matching expressions.
A val
or var
in a type that represents part, if not all of the state of a corresponding instance of the type.
Keyword for declarations. For types, final
prevents users from subclassing the type. For type members, final
prevents users from overriding the members.
An adjective indicating that the applicable “thing” is a first-class value in the language, meaning you can assign instances to variables, pass them as function parameters, and return them from functions. Often used to refer to functions, which are first-class values in Scala and other functional programming languages.
Another name for Scala’s for
expression.
Another name for a function argument, used in the context of binding the free variables in the function.
A variable that is referenced in a function literal, but is not passed in as an argument. Therefore, it must be “bound” to a defined variable of the same name in the context where the function literal is defined, to form a closure.
In Scala, the term function is used for a function that is not tied to a particular object or class. Contrast with method. Functions are instances of FunctionN
types, where N
is the arity of the function.
Scala’s term for an anonymous function expression, from which closures are created.
In Scala, all functions are instances of FunctionN[-T1, T2, …, TN, +R]
types, where N
is the number of arguments (0 through 22 are supported). The type signature syntax (T1, T2, …, TN) ⇒ R
is used for declaring concrete instances, i.e., function literals.
A form of programming that mimics the way mathematical functions and variables work. Mathematical functions are side-effect free and they are composable from other functions. Variables are assigned once. Functions can be assigned to variables and returned from other functions.
Expressions like i <- listOfInts
in for expressions. Each pass through the loop generates a new val i
taken from the list listOfInts
, in this example.
Another term for parameterized types, used more often in Java than Scala.
Functions that take other functions as arguments or return a function value.
A value that can’t be changed after it has been initialized. Contrast with mutable value.
The quality of many object-oriented and “procedural” programs where the code consists of statements directing the system to take a particular sequence of actions. Contrast with declarative programming.
A Scala keyword used to mark a method or function value as eligible for use as an implicit type conversion. The keyword is also used to mark an implicit argument.
A method or function value that is marked with the implicit keyword, marking it as eligible for use as an implicit type conversion, whenever it is in scope and conversion is needed (e.g., for the pimp my library pattern).
Method arguments that are optional for the user to specify and indicated with the implicit
keyword. If the user does not specify a value for the argument, a default value is used instead, which is either an in-scope value of the same type or the result of calling an in-scope, no-argument method that returns an instance of the same type. See also default argument value.
A data structure that represents a non-terminating collection of values, but which is capable of doing so without exhausting system resources. The values are not computed until the data structure is asked to produce them. As long as only a finite subset of the values are requested, resource exhaustion is avoided.
A syntax supported by the compiler for methods with one argument. The method can be invoked without the period between the object and the method name and without the parentheses around the argument. When used for methods named with operator characters, the syntax provides a form of operator overloading. Sometimes also called operator notation. See also postfix notation.
When a parameterized type of the form Op[A,B]
is used to instantiate a type, it can also be written as A Op B
. For example, Or[Throwable,Boolean]
can be written Throwable Or Boolean
.
A strong relationship between one class or trait and another class or trait. The inheriting (derived) class or trait incorporates the members of the parent class or trait, as if they were defined within the derivative. The derivative may override inherited members (in most cases). Instances of a derivative are substitutable for instances of the parent.
An object created by invoking a class constructor. The word object is synonymous in most object-oriented languages, but we use the term object to refer to an explicitly-declared Scala object and we use the term instance (and the verb instantiate) for the more general case.
Instantiation can also refer to creating a concrete type from a parameterized type by specifying concrete types for the parameters.
In the context of the variance behavior of parameterized types under inheritance, if a parameter A
is invariant in a parameterized type T[A]
, then there is no variance annotation and a type T[B]
is a subtype of T[A]
if and only if B
equals A
. That is, the type can’t be changed. See also covariance and contravariance.
In the context of design by contract, an assertion that should be true before and after a method is executed.
The idea that an object should not instantiate it’s own copies of external dependencies, but rather rely on other mechanisms to supply those dependencies. IoC promotes better decoupling and testability, as the object only knows about the abstractions of its dependencies, not specific concrete implementers of them. A weak form of IoC is when an object calls a factory, service locator, etc. to obtain the dependents. Hence, the object still has an active role and it has a dependency on the “provider”. The strongest form of IoC is dependency injection, where the object remains “passive”.
Immutable variables (vals
) can be declared lazy
, meaning they will only be evaluated when they are read. This feature is useful for expensive evaluations that may not be needed.
Lazy data structures can also be used to define infinite data structures that won’t exhaust system resources as long as only a finite subset of the structure is evaluated. The Stream
and Range
classes are both lazy. Contrast with strict.
The algorithm used for a type to resolve member lookup, such as overridden methods, including calls to super
.
Used to refer to “literal” value expressions, such as numbers (e.g., 1
, 3.14
), strings (e.g., "Hello Scala!"), tuples (e.g., (1, 2, 3)
), and function literals (e.g., (x) ⇒ x + x
).
See type bounds.
The queue were an actor’s messages are stored until the actor processes them in the actor model of concurrency.
The entry function for an application that is invoked by the runtime is called main
. The name dates back to the C language. In Scala, a main
method must be defined in an object
. Java, by way of contrast, requires a main
method to be defined as a static method of a class
.
A divide and conquer strategy for processing large data sets in parallel. In the “map” phase, the data sets are subdivided. The desired computation is performed on each subset. The “reduce” phase combines the results of the subset calculations into a final result. MapReduce frameworks handle the details of managing the operations and the nodes they run on, including restarting operations that fail for some reason. The user of the framework only has to write the algorithms for mapping and reducing the data sets and computing with the subsets.
A generic term for a type, field, or method declared in a class or trait.
A form of caching that optimizes function invocations. The results from a function’s invocations are saved so that when repeated invocations with the same inputs are made, the cached results can be returned instead of re-invoking the function again.
In the actor model of concurrency, messages are exchanged between actors to coordinate their work.
In object-oriented programming, method invocation is sometimes referred to as “sending a message to an object”, especially in certain languages, like Smalltalk and to some extent, Ruby.
A function that is associated exclusively with an instance, either defined in a class, trait, or object definition. Methods can only be invoked using the object.method
syntax.
A narrowly-focused encapsulation of state and behavior that is more useful as an adjunct to another object’s state and behavior, rather than standing on its own. Mixins in Scala are implemented using traits.
In some languages, but not Scala, a type can extend more than one parent class. Compare to single inheritance.
A value that can be changed after it has been initialized. Contrast with immutable value.
(Scala version 2.8) The ability to refer to a method argument by name when calling the method. It is useful in combination with default argument values for minimizing the number of arguments that have to be specified by the caller.
An item in a grammar that requires further decomposition into one or more nonterminals (including possibly a recursive reference to itself) and terminals.
An cohesive unit with a particular state, possible state transitions, and behaviors. In Scala, the keyword object
is used to declare a singleton explicitly, using the same syntax as class declarations, except for the lack of constructor parameters and auxiliary parameters (because objects
are instantiated by the Scala runtime, not by user code). To avoid confusion with objects
, we use the term instance to refer to instances of classes and objects
generically.
A form of programming that encapsulates state values and operations on that state, exposing a cohesive abstraction to clients of the object while hiding internal implementation details. OOP also supports subtyping to define specializations and “family” relationships between types.
Characters like ‘<’, ‘*’, etc. that are not letters, digits, nor reserved characters, like left and right parentheses, “curly” braces, “square” brackets, the semicolon, colon, or comma. These characters can be used in method names to implement a form of operator overloading.
See infix notation.
The feature in some languages where standard mathematical operators, like ‘*’, ‘/’, ‘<’, etc. can be defined by users for custom types. In Scala, a form of operator overloading is supported by allowing operator characters to be used as normal method names and by allowing methods with one argument to be invoked with infix notation. The “operator precedence” for these methods is determined by the first character, e.g., method *< will have higher precedence than method +<.
Two or more functions defined in the same scope (e.g., as methods in a type or as “bare” functions) that have the same name, but different signatures.
A special kind of object declaration that declares members that should be visible at the scope of the named package. For example, for the declaration package object math { type Complex = … }
, the Complex
type can be referenced as math.Complex
. (Scala version 2.8)
Parsers for parsing expression grammars (PEGs) [Ford]. They have several benefits, such as lack of ambiguity and good performance characteristics. The forthcoming Scala version 2.8 parser combinator library will add support for creating packrat parsers.
Scala’s analog of generics in Java. Parameterized types are defined with placeholder parameters for types they use. When an instance of a parameterized type is created, specific types must be specified to replace all the type parameters. See also type constructor.
A class or trait from which another class or trait is derived. Also called a supertype or base type. See inheritance.
An alternative to context-free grammars that provide guaranteed linear-time parsing using memoization and unambiguous grammars [PEG].
Associated with currying, where a subset of a curried functions arguments are applied, yielding a new function that takes the remaining arguments.
A function that is not valid over the whole range of its arguments. Pattern matching expressions can be converted to partial functions by the compiler in some contexts.
A nested type T is unique based on its “path”, the hierarchical, period-delimited list of the the enclosing packages, the enclosing types, and finally the type T itself. Instances of T can have different, incompatible types. For example, if T is nested in a trait and the trait appears in the linearizations of different types, then the instances in those Ts will have different types.
Case expressions, usually in a match expression, that compare an object against possible types, type extractors, regular expressions, etc. to determine the appropriate handling.
The name of a design pattern that appears to add new methods to a type. It uses an implicit type conversion to automatically wrap the type in a wrapper type, where the wrapper type has the desired methods.
An assertion that should be true on entry to a method or other entry point. See design by contract.
An assertion that should be true on exit from a method or other boundary point. See design by contract.
A syntax supported by the compiler for methods with no argument, sometimes called nullary methods. The method can be invoked without the period between the object and the method name. See also infix notation.
The main constructor of a class, consisting of the class body with the parameter list specified after the name of the class. See also auxiliary constructor.
A non-object type on the underlying runtime platform (e.g., JVM and .NET). Scala does not have primitive types at the source code level. Rather, it uses value types, which are subclasses of AnyVal
, to wrap runtime primitives, providing object semantics at the code level, while using boxing and unboxing of primitives at the byte code level to optimize performance.
A term used for each part of a grammar that decomposes a specific nonterminal into other nonterminals (perhaps including a recursive reference to the original nonterminal) and terminals.
Used in the context of functions to mean that they are side-effect free. See also referential transparency.
When a function calls itself as part of its computation. A termination condition is required to prevent an infinite recursion. See also tail-call recursion.
A type whose instances are implemented as objects on the runtime platform. All reference types subtype AnyRef
.
The property of an expression, such as a function, where it can be replaced with its value without changing the behavior of the code. This can be done with side-effect free functions when the inputs are the same. The primary benefit of referential transparency is that it is easy to reason about the behavior of a function, without having to understand the context in which it is invoked. That makes the function easier to test, refactor, and reuse.
The term used for adding or overriding members in a type body for a compound type.
Where the specific types used when instantiating a generic type are retained in the byte code, so the information is available at runtime. This is a property of .NET byte code, but not JVM byte code, which uses type erasure. To minimize incompatibilities, both the Java and .NET Scala versions use type erasure.
A name given to interactive language interpreters, like the scala
command in interpreter mode. REPL is an acronym for Read, Evaluate, Print, Loop.
The API documented generated form Scala source code using the scaladoc
tool, analogous to Java’s Javadocs.
A defined boundary of visibility, constraining what types and their members are visible within it.
Keyword for parent classes when all the direct subclasses allowed are defined in the same source file.
A declaration in a trait or class that changes its type, sometimes with an alias for this
defined (self
is conventional). A self type can be used to indicate dependencies on other traits that will have to be mixed into a concrete instance to resolve the dependency. In some cases, these dependencies are used to ensure that an instance of the current type can be used as an instance of a dependent type in certain contexts (e.g., as used in the Observer Pattern in the section called “Self-Type Annotations and Abstract Type Members” in Chapter 13, Application Design).
Functions or expressions that have no side effects, meaning they modify no global or “object” state.
For a function, the name, parameter list types, and return value. For a method, also includes the type that defines the method.
A class, object, or trait can extend one parent class. Compare to multiple inheritance.
A class that has only one instance. In Scala, singletons are declared using the keyword object
instead of class
.
The unique type designator that excludes path dependencies. If p1
and p2
are two different path dependent types, their singleton types are p1.type
and p2.type
, which may be the same. Contrast with singleton objects. Singleton types are not specifically the types of singleton objects, but singleton objects do have singleton types.
Used in the context of path-dependent types, all but the last elements in the path must be stable, which roughly means that they are either packages, singleton objects, or type declarations that alias the same.
As in, “the state of an object”, where it informally means the set of all the current values of an object’s fields.
Loosely speaking, early binding of type information, sometimes referred to as binding to a reference, rather than the value to which the reference is assigned.
Used to refer to data structures that are not lazy, i.e., they are defined “eagerly” by the expressions used to construct them.
A structural type is like an anonymous type, where only the “structure” a candidate type must support is specified, such as members that must be present. Structural types do not name the candidate types that can match, nor do any matching types need to share a common parent trait or class with the structural type. Hence, structural types are a type-safe analog to duck typing in dynamically-typed languages, like Ruby.
A synonym for derived type.
A synonym for parent type.
An interned string. Literal symbols are written starting with a single “right quote”, e.g., 'name
.
A form of recursion where a function calls itself as the last thing it does, i.e., it does no additional computations with the result of the recursive call. The Scala compiler will optimize tail-call recursions into a loop.
A development discipline where no new functionality is implemented until a test has been written that will pass once the functionality is implemented. See also behavior-driven development.
A token in a grammar, such as a keyword, that requires no further decomposition. See also nonterminal.
When testing the behavior of one object, a test double is another object that satisfies a dependency in the object under test. The test double may assist in the testing process, provide controlled test data and behaviors, and very aspects of the interaction between the object under test and the test double. Specific types of test doubles include “fakes”, “mocks”, and “stubs”.
A class-like encapsulation of state (fields) and behavior (methods) that is used for mixin composition. Zero or more traits can be mixed into class declarations or when creating instances directly, effectively creating an anonymous class.
A loop that iterates through a list of functions, invoking each in turn. The metaphor of bouncing the functions off a trampoline is the source of the name. It can be used to rewrite a form of recursion where a function doesn’t call itself, but rather calls a different function which invokes the original function, and so forth, back and forth. There is a proposal for the Scala version 2.8 compiler to include a trampoline implementation.
A grouping of two or more items of arbitrary types into a “Cartesian product”, without first defining a class to hold them. Literal tuple values are written in parentheses and separated by commas, e.g., (x1, x2, …)
. They are first-class values, so you can assign them to variables, pass them as values, and return them from functions. Tuples are represented by TupleN
classes, for N between 2 and 22, inclusive.
A categorization of allowed states and operations on those states, including transformations from one state to another. The type of an instance is the combination of its declared class (explicitly named or anonymous), mixed in traits, and the specific types used to resolve any parameters if the class or traits are parameterized types. In Scala, type
is also a keyword. When indicated in the text, we sometimes use the term type to refer to a class, object, or trait generically.
An explicit declaration of the type of a value, e.g., count: Int
, where Int
is the type annotation. A type annotation is required when type inference can’t be used. In Scala, function parameters require type annotations and annotations are required in some other contexts where the type can’t be inferred, e.g., for return values of some functions.
Constraints on the allowed types that can be used for a parameter in a parameterized type or assigned to an abstract type. In Scala, the expression A <: B
defines an upper bound on A
, it must be a subtype or the same as B
. The expression A >: B
defines a lower bound on A
, it must be a supertype or the same as B
.
Informally, a parameterized type is sometimes called a type constructor, although a “non-parameterized” type is really a type constructor, too, just with zero parameters! The analogy with an instance constructor is that you specify specific concrete types for the parameters to create a new concrete type, just as you specify values to an instance constructor to create an instance.
The conventional type ids commonly used, e.g., class Person
, object O { type t }
, etc.. They are actually a short hand syntax for type projections.
A property of the generics type model on the JVM. When a type is created from a generic, the information about the specific types substituted for the type parameters is not stored in the byte code and is therefore not available at run time. Scala must follow the same model. So, for example, instances of List[String]
and List[Int]
are indistinguishable. Contrast with reified types.
Inferring the type of a value based on the context in which it is used, rather than relying on explicit type annotations. Sometimes called implicit typing.
A way to refer to a type nested within another type. For example, if a type t
is declared in a class C
, then the type projection for t
is C#t
.
When a parameterized type is declared, the variance behavior under inheritance of each type parameter can be specified using a type variance annotation on the type symbol.
On a type parameter in a parameterized types, a +
prefixed to the type symbol is used to indicate covariance. A -
prefix on the type symbol is used to indicate contravariance. No variance annotation is used to indicate invariance (the default).
See type bounds.
The actual state of an instance, usually in the context of a variable that refers to the instance. See also value type.
An immutable instance or object.
A subclass of AnyVal
that wraps a corresponding non-object “primitive” type on the runtime platform (e.g., JVM and .NET). The value types are Boolean
, Char
, Byte
, Double
, Float
, Long
, Int
, and Short
. (Unit
is also a value type.) All are declared abstract final
so they can’t be used in new V
expressions. Instead, programs specify literal values, e.g., 3.14
for a Double
or use methods that return new values. The Scala runtimes handles instantiation. All the instances of value types are immutable value objects.
The term value type is also used to mean the categories of types for instances. That is, the type of every instance must fall into one of several categories: annotated types, compound types, function types, infix types, parameterized types, tuples, type designators, type projections, singleton types.
A named reference to a value. If the variable is declared with the val
keyword, a new value can’t be assigned to the variable. If the variable is declared with the var
keyword, a new value can be assigned to the variable. The value a variable references must be type compatible with the declared or inferred type of the variable.
An implicit value of function type that converts a type A
to B
. The function has the type A => B
or (=> A) => B
(In the later case, the (=> A)
is a by-name parameter). An in-scope implicit type conversion method with the same signature can also be used as a view.
A type specification of the form A <% B
, which says that any type can be used for A
as long as an in-scope view exists that can convert an A
to a B
.
The scope in which a declared type or type member is visible to other types and members.
No comments yet
Add a comment