@@ -4,7 +4,7 @@ title: Overview
4
4
5
5
partof : reflection
6
6
num : 1
7
- outof : 6
7
+ outof : 6
8
8
languages : [ja]
9
9
---
10
10
@@ -13,37 +13,38 @@ languages: [ja]
13
13
** Heather Miller, Eugene Burmako, Philipp Haller**
14
14
15
15
* Reflection* is the ability of a program to inspect, and possibly even modify
16
- itself at runtime. It has a long history across object-oriented, functional,
17
- and logic programming paradigms, with each paradigm evolving its own,
18
- sometimes markedly different, * status quo* for reflection. While more
19
- functional programming languages like Lisp/Scheme have focused primarily on
20
- reification to enable tasks like dynamic interpretation, object-oriented
21
- programming languages like Java have focused primarily on runtime reflection to
22
- enable tasks like the inspection and/or invocation of class members at runtime.
23
-
24
- Three principal use cases of reflection across languages and paradigms are:
25
-
26
- 1 . ** Runtime Reflection** . The ability to inspect and invoke runtime types and their members.
27
- 2 . ** Compile-time Reflection** . The ability to access and manipulate abstract syntax trees at compile time.
28
- 3 . ** Reification** . The generation of abstract syntax trees at runtime in the case of (1), or at compile time in the case of (2).
16
+ itself. It has a long history across object-oriented, functional,
17
+ and logic programming paradigms.
18
+ While some languages are built around reflection as a guiding principle, many
19
+ languages progressively evolve their reflection abilities over time.
20
+
21
+ Reflection involves the ability to ** reify** (ie. make explicit) otherwise-implicit
22
+ elements of a program. These elements can be either static program elements
23
+ like classes, methods, or expressions, or dynamic elements like the current
24
+ continuation or execution events such as method invocations and field accesses.
25
+ One usually distinguishes between compile-time and runtime reflection depending
26
+ on when the reflection process is performed. ** Compile-time reflection**
27
+ is a powerful way to develop program transformers and generators, while
28
+ ** runtime reflection** is typically used to adapt the language semantics
29
+ or to support very late binding between software components.
29
30
30
31
Until 2.10, Scala has not had any reflection capabilities of its own. Instead,
31
- one could use Java reflection which provided a very limited subset of runtime
32
- reflection capabilities from point (1) above. However, many Scala-specific types are
33
- simply unrecoverable under standalone Java reflection; including info about
34
- runtime existential, higher-kinded, path-dependent and abstract types. In
35
- addition to these Scala-specific types, Java reflection is also unable to
36
- recover runtime type info of Java types that are generic at compile-time; a
37
- restriction that carried through to runtime reflection on generic types in
38
- Scala.
32
+ one could use part of the Java reflection API, namely that dealing with providing
33
+ the ability to dynamically inspect classes and objects and access their members.
34
+ However, many Scala-specific elements are unrecoverable under standalone Java reflection,
35
+ which only exposes Java elements (no functions, no traits)
36
+ and types (no existential, higher-kinded, path-dependent and abstract types).
37
+ In addition, Java reflection is also unable to recover runtime type info of Java types
38
+ that are generic at compile-time; a restriction that carried through to runtime
39
+ reflection on generic types in Scala.
39
40
40
41
In Scala 2.10, a new reflection library was introduced not only to address the shortcomings
41
- of Java' s runtime reflection on Scala-specific and generic types, but to also
42
- add a more powerful toolbox of general reflective capabilities to Scala. Along
43
- with full-featured runtime reflection for Scala types and generics (1) , Scala 2.10 also
42
+ of Java’ s runtime reflection on Scala-specific and generic types, but to also
43
+ add a more powerful toolkit of general reflective capabilities to Scala. Along
44
+ with full-featured runtime reflection for Scala types and generics, Scala 2.10 also
44
45
ships with compile-time reflection capabilities, in the form of
45
- [ macros] ({{site.baseurl }}/overviews/macros/overview.html) (2) , as well as the
46
- ability to * reify* Scala expressions into abstract syntax trees (3) .
46
+ [ macros] ({{site.baseurl }}/overviews/macros/overview.html), as well as the
47
+ ability to * reify* Scala expressions into abstract syntax trees.
47
48
48
49
## Runtime Reflection
49
50
@@ -342,4 +343,4 @@ For more details, see the section of this guide on
342
343
[ Mirrors] ({{ site.baseurl}}/overviews/reflection/environment-universes-mirrors.html),
343
344
or the
344
345
[ Mirrors API docs] (http://www.scala-lang.org/api/{{ site.scala-version}}/scala/reflect/api/Mirrors.html)
345
- in package ` scala.reflect.api ` .
346
+ in package ` scala.reflect.api ` .
0 commit comments