Skip to content

Instantly share code, notes, and snippets.

@amaembo
Created June 4, 2020 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amaembo/469ea115f525fc4b314344993baba7b9 to your computer and use it in GitHub Desktop.
Save amaembo/469ea115f525fc4b314344993baba7b9 to your computer and use it in GitHub Desktop.
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