Format annotation attributes

This commit is contained in:
ktkk 2026-07-07 13:38:46 +00:00
parent 3a5fd90d14
commit f12bcd2911
6 changed files with 275 additions and 16 deletions

View file

@ -0,0 +1,14 @@
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)
@CustomAnnotationAnnotation
public @interface CustomAnnotation {
public CustomAnnotationType type();
public String name() default "Bob";
}

View file

@ -0,0 +1,9 @@
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.ANNOTATION_TYPE)
public @interface CustomAnnotationAnnotation { }

View file

@ -0,0 +1,5 @@
public enum CustomAnnotationType {
ONE,
TWO,
}

View file

@ -4,7 +4,6 @@ import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface CustomAttribute {
}
@Target(ElementType.PARAMETER)
public @interface CustomParameterAnnotation { }

View file

@ -1,11 +1,12 @@
import java.util.function.Supplier;
@CustomAnnotation(type = CustomAnnotationType.ONE, name = "Alice")
public class Main implements Runnable, Supplier<Integer>, Interface {
private static final String name = "John";
private static final int number = 42;
private static final double funnyNumber = 6.9;
public static void main(String[] args) {
public static void main(@CustomParameterAnnotation String[] args) {
final var main = new Main();
main.sayHello();