Skip to content

Instantly share code, notes, and snippets.

Created Jun 4, 2020
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) { }
@interface Foo {String value();}
public static void main(String[] args) {
Constructor<?> constructor = MyEnum.class.getDeclaredConstructors()[0];
Parameter[] parameters = constructor.getParameters();
.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