Skip to content

Instantly share code, notes, and snippets.

@amaembo
Created Jun 4, 2020
Embed
What would you like to do?
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.Arrays;
enum MyEnum {
A(0.0, 0, "");
MyEnum(@Foo("double annotated") double d,
int i,
@Foo("string annotated") String s) { }
@Retention(RetentionPolicy.RUNTIME)
@interface Foo {String value();}
public static void main(String[] args) {
Constructor<?> constructor = MyEnum.class.getDeclaredConstructors()[0];
Parameter[] parameters = constructor.getParameters();
Arrays.stream(parameters)
.filter(p -> p.getType() == double.class)
.forEach(p -> System.out.println(p.getAnnotation(Foo.class).value()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment