Created
June 4, 2020 10:56
-
-
Save amaembo/469ea115f525fc4b314344993baba7b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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