Skip to content

Commit 4afb734

Browse files
blakehawkinsshekhargulati
authored andcommitted
reflow paragraphs in section 12 (#15)
1 parent e256e8e commit 4afb734

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

12-annotations.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Annotation Improvements
22
-------
33

4-
There are couple of improvements made in the annotation mechanism in Java 8. These are:
4+
There are couple of improvements made in the annotation mechanism in Java 8.
5+
These are:
56

67
1. Repeatable annotations
78
2. Type annotations
@@ -10,7 +11,10 @@ There are couple of improvements made in the annotation mechanism in Java 8. The
1011
1112
## Repeatable annotations
1213

13-
Before Java 8, it was not possible to use same annotation twice at the same location i.e. you can't use annotation `@Foo` twice on a method. If you have used JPA then you would have use an annotation called `@JoinColumns` that allows wraps multiple `@JoinColumn` annotation as shown below.
14+
Before Java 8, it was not possible to use same annotation twice at the same
15+
location i.e. you can't use annotation `@Foo` twice on a method. If you have
16+
used JPA then you would have use an annotation called `@JoinColumns` that allows
17+
wraps multiple `@JoinColumn` annotation as shown below.
1418

1519
```java
1620
@ManyToOne
@@ -30,14 +34,18 @@ In Java 8, you can write the same as shown below because with Java 8 you can rep
3034
public Address getAddress() { return address; }
3135
```
3236

33-
34-
***With Java 8 you can use same annotation type multiple times possibly with different arguments at any location(class, method, field declaration) in your Java code.***
37+
***With Java 8 you can use same annotation type multiple times possibly with
38+
different arguments at any location(class, method, field declaration) in your
39+
Java code.***
3540

3641
### Writing your own repeatable Annotations
3742

3843
To write your own repeatable annotation you have to do the following:
3944

40-
**Step 1:** Create an annotation with `@Repeatable` annotation as shown below. `@Repeatable` annotation requires you to specify a mandatory value for the container type that will contain the annotation. We will create container annotation in step 2.
45+
**Step 1:** Create an annotation with `@Repeatable` annotation as shown below.
46+
`@Repeatable` annotation requires you to specify a mandatory value for the
47+
container type that will contain the annotation. We will create container
48+
annotation in step 2.
4149

4250
```java
4351
import java.lang.annotation.*;
@@ -70,7 +78,10 @@ public void manage() {
7078
}
7179
```
7280

73-
If you have to find all the repeatable annotations on a method then you can use `getAnnotationsByType` method that is now available on `java.lang.Class` and `java.lang.reflect.Method`. To print all the vm names, you can write code as shown below.
81+
If you have to find all the repeatable annotations on a method then you can use
82+
`getAnnotationsByType` method that is now available on `java.lang.Class` and
83+
`java.lang.reflect.Method`. To print all the vm names, you can write code as
84+
shown below.
7485

7586
```java
7687
CreateVm[] createVms = VmManager.class.getMethod("manage").getAnnotationsByType(CreateVm.class);
@@ -79,7 +90,8 @@ Stream.of(createVms).map(CreateVm::name).forEach(System.out::println);
7990

8091
## Type annotations
8192

82-
You can now apply annotations at two more target locations -- TYPE_PARAMETER and TYPE_USE.
93+
You can now apply annotations at two more target locations -- TYPE_PARAMETER and
94+
TYPE_USE.
8395

8496
```java
8597
@Retention(RetentionPolicy.RUNTIME)

0 commit comments

Comments
 (0)