+java annotation test
This commit is contained in:
parent
8636aef269
commit
37fe21c335
9
Java/annotations/AnnotSniffer.java
Normal file
9
Java/annotations/AnnotSniffer.java
Normal file
@ -0,0 +1,9 @@
|
||||
public class AnnotSniffer {
|
||||
public static void sniff(Class c) {
|
||||
if (c.isAnnotationPresent(annot.class)) {
|
||||
System.out.println("Bar");
|
||||
} else {
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
}
|
9
Java/annotations/Main.java
Normal file
9
Java/annotations/Main.java
Normal file
@ -0,0 +1,9 @@
|
||||
@annot
|
||||
public class Main {
|
||||
public static void main(String args[]) {
|
||||
System.out.print("Foo");
|
||||
AnnotSniffer.sniff(Main.class);
|
||||
MyGeneric<Integer> a = new MyGeneric<>(10);
|
||||
MyGeneric<?> b = new MyGeneric<>("asd");
|
||||
}
|
||||
}
|
7
Java/annotations/MyGeneric.java
Normal file
7
Java/annotations/MyGeneric.java
Normal file
@ -0,0 +1,7 @@
|
||||
public class MyGeneric<T> {
|
||||
private T val;
|
||||
|
||||
public MyGeneric(T v) {
|
||||
this.val = v;
|
||||
}
|
||||
}
|
9
Java/annotations/annot.java
Normal file
9
Java/annotations/annot.java
Normal file
@ -0,0 +1,9 @@
|
||||
//import java.lang.annotation.*;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface annot {}
|
Loading…
x
Reference in New Issue
Block a user