From 37fe21c33580c801acff0b32be64ef7d0492950a Mon Sep 17 00:00:00 2001 From: anon Date: Tue, 10 Dec 2024 20:36:31 +0100 Subject: [PATCH] +java annotation test --- Java/annotations/AnnotSniffer.java | 9 +++++++++ Java/annotations/Main.java | 9 +++++++++ Java/annotations/MyGeneric.java | 7 +++++++ Java/annotations/annot.java | 9 +++++++++ 4 files changed, 34 insertions(+) create mode 100644 Java/annotations/AnnotSniffer.java create mode 100644 Java/annotations/Main.java create mode 100644 Java/annotations/MyGeneric.java create mode 100644 Java/annotations/annot.java diff --git a/Java/annotations/AnnotSniffer.java b/Java/annotations/AnnotSniffer.java new file mode 100644 index 0000000..960117d --- /dev/null +++ b/Java/annotations/AnnotSniffer.java @@ -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(""); + } + } +} diff --git a/Java/annotations/Main.java b/Java/annotations/Main.java new file mode 100644 index 0000000..7788bd2 --- /dev/null +++ b/Java/annotations/Main.java @@ -0,0 +1,9 @@ +@annot +public class Main { + public static void main(String args[]) { + System.out.print("Foo"); + AnnotSniffer.sniff(Main.class); + MyGeneric a = new MyGeneric<>(10); + MyGeneric b = new MyGeneric<>("asd"); + } +} diff --git a/Java/annotations/MyGeneric.java b/Java/annotations/MyGeneric.java new file mode 100644 index 0000000..ffb18e0 --- /dev/null +++ b/Java/annotations/MyGeneric.java @@ -0,0 +1,7 @@ +public class MyGeneric { + private T val; + + public MyGeneric(T v) { + this.val = v; + } +} diff --git a/Java/annotations/annot.java b/Java/annotations/annot.java new file mode 100644 index 0000000..300b21c --- /dev/null +++ b/Java/annotations/annot.java @@ -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 {}