From b44c5980ac2f1e330acd522badabb01f5eb50c06 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Mon, 10 Mar 2014 16:58:12 -0700 Subject: github markdown: code blocks --- 13-user-defined-annotations.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to '13-user-defined-annotations.md') 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 = - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ``` * `@throws()` \ 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, -- cgit v1.2.3