Skip to content

Commit 88b18cf

Browse files
committed
Merge branch 'master' of https://github.com/ramram43210/Java
2 parents 4a9cd08 + 3c5af6d commit 88b18cf

9 files changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>AnnotationDemo</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8
Binary file not shown.
403 Bytes
Binary file not shown.
315 Bytes
Binary file not shown.
484 Bytes
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class RepeatingAnnotations
2+
{
3+
4+
public static void main(String[] args)
5+
{
6+
7+
/*
8+
* Retrieving Annotations using Reflection API
9+
* method
10+
*/
11+
Schedules schedules = ServerRestartSchedule.class
12+
.getAnnotation(Schedules.class);
13+
System.out.println(schedules);
14+
Schedule[] scheduleArray = schedules.value();
15+
for (Schedule schedule : scheduleArray)
16+
{
17+
System.out.println(schedule + " , dayOfMonth = "
18+
+ schedule.dayOfMonth() + " , dayOfWeek = "
19+
+ schedule.dayOfWeek() + " , hour = " + schedule.hour());
20+
}
21+
22+
}
23+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.lang.annotation.Repeatable;
2+
import java.lang.annotation.Retention;
3+
import java.lang.annotation.RetentionPolicy;
4+
5+
/*
6+
* Step 1: Declare a Repeatable Annotation Type
7+
*
8+
* The annotation type must be marked with the
9+
*
10+
* @Repeatable meta-annotation.
11+
*
12+
* The value of the @Repeatable meta-annotation, in
13+
* parentheses, is the type of the container
14+
* annotation that the Java compiler generates to
15+
* store repeating annotations. In this example, the
16+
* containing annotation type is Schedules, so
17+
* repeating @Schedule annotations is stored in an
18+
* @Schedules annotation.
19+
*/
20+
21+
@Repeatable(Schedules.class)
22+
@interface Schedule
23+
{
24+
25+
String dayOfMonth() default "first";
26+
27+
String dayOfWeek() default "Mon";
28+
29+
int hour() default 12;
30+
}
31+
32+
/*
33+
* Step 2: Declare the Containing Annotation Type
34+
*
35+
* The containing annotation type must have a value element
36+
* with an array type. The component type of the array type
37+
* must be the repeatable annotation type.
38+
*/
39+
@Retention(RetentionPolicy.RUNTIME)
40+
@interface Schedules
41+
{
42+
Schedule[] value();
43+
}
44+
45+
@Schedule
46+
@Schedule(dayOfMonth = "second", dayOfWeek = "Tue", hour = 17)
47+
@Schedule(dayOfMonth = "third", dayOfWeek = "Wed", hour = 24)
48+
public class ServerRestartSchedule
49+
{
50+
51+
}

0 commit comments

Comments
 (0)