+java annotation test

This commit is contained in:
anon 2024-12-10 20:36:31 +01:00
parent 8636aef269
commit 37fe21c335
4 changed files with 34 additions and 0 deletions

View 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("");
}
}
}

View 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");
}
}

View File

@ -0,0 +1,7 @@
public class MyGeneric<T> {
private T val;
public MyGeneric(T v) {
this.val = v;
}
}

View 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 {}