summaryrefslogtreecommitdiff
path: root/13-user-defined-annotations.md
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2014-03-10 16:58:12 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-03-10 16:58:12 -0700
commitb44c5980ac2f1e330acd522badabb01f5eb50c06 (patch)
treed8a128c8ce8a46c46d2b468e6b51b33113a971b4 /13-user-defined-annotations.md
parent9dec37b50be3288822b9c7c0cb5c4d263f3d05e7 (diff)
downloadscala-b44c5980ac2f1e330acd522badabb01f5eb50c06.tar.gz
scala-b44c5980ac2f1e330acd522badabb01f5eb50c06.tar.bz2
scala-b44c5980ac2f1e330acd522badabb01f5eb50c06.zip
github markdown: code blocks
Diffstat (limited to '13-user-defined-annotations.md')
-rw-r--r--13-user-defined-annotations.md24
1 files changed, 12 insertions, 12 deletions
diff --git a/13-user-defined-annotations.md b/13-user-defined-annotations.md
index 1aa5e7e613..717a6dcb1f 100644
--- a/13-user-defined-annotations.md
+++ b/13-user-defined-annotations.md
@@ -1,9 +1,9 @@
# User-Defined Annotations
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
Annotation ::= ‘@’ SimpleType {ArgumentExprs}
ConstrAnnotation ::= ‘@’ SimpleType ArgumentExprs
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
User-defined annotations associate meta-information with definitions.
A simple annotation has the form `@$c$` or `@$c(a_1 , \ldots , a_n)$`.
@@ -20,12 +20,12 @@ does not matter.
Examples:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
@serializable class C { ... } // A class annotation.
@transient @volatile var m: Int // A variable annotation
String @local // A type annotation
(e: @unchecked) match { ... } // An expression annotation
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
The meaning of annotation clauses is implementation-dependent. On the
Java platform, the following annotations have a standard meaning.
@@ -55,9 +55,9 @@ Java platform, the following annotations have a standard meaning.
This is equivalent to a the following field
definition in Java:
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ```
private final static SerialVersionUID = <longlit>
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ```
* `@throws(<classlit>)` \
A Java compiler checks that a program contains handlers for checked exceptions
@@ -95,11 +95,11 @@ Java platform, the following annotations have a standard meaning.
matches which would otherwise be emitted. For instance, no warnings
would be produced for the method definition below.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ```
def f(x: Option[Int]) = (x: @unchecked) match {
case Some(y) => y
}
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ```
Without the `@unchecked` annotation, a Scala compiler could
infer that the pattern match is non-exhaustive, and could produce a
@@ -110,12 +110,12 @@ Java platform, the following annotations have a standard meaning.
value to appear in a path, even if its type is [volatile](#volatile-types).
For instance, the following member definitions are legal:
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ```
type A { type T }
type B
@uncheckedStable val x: A with B // volatile type
val y: x.T // OK since `x' is still a path
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ```
Without the `@uncheckedStable` annotation, the designator `x`
would not be a path since its type `A with B` is volatile. Hence,
@@ -135,11 +135,11 @@ Java platform, the following annotations have a standard meaning.
For instance, the following code would generate specialized traits for
`Unit`, `Int` and `Double`
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ```
trait Function0[@specialized(Unit, Int, Double) T] {
def apply: T
}
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ```
Whenever the static type of an expression matches a specialized variant of
a definition,