java - getFieldsAnnotatedWith annotation containing -


annotation

@target(elementtype.field) @retention(retentionpolicy.runtime) public @interface searchable {     searchtype[] types() default { searchtype.all }; } 

reflections in method

reflections reflections = new reflections(packagename); reflections.getfieldsannotatedwith(); // here's problem 

i return fields annotated searchable containing @ least searchtype.all. have tried defining new searchable() { ... } pass method. though result in fields exact match. e.g. containing searchtype.all. way:

new searchable() {         @override public searchtype[] types() { return { searchtype.all }; }         @override public class<? extends annotation> annotationtype() { return searchable.class; }         } 

i fields @searchable(types = { searchtype.all, searchtype.text }) hit too, since contains searchtype.all. how can accomplish this?

i don't know reflections api, can fields annotated searchable annotation, , check if searchable annotation's types contains searchtype.all:

set<field> fields = reflections.getfieldsannotatedwith(searchable.class); set<field> wanted = new hashset<field>(); (field field : fields) {     searchable annotation = field.getannotation(searchable.class);     if (arrays.aslist(annotation.types).contains(searchtype.all)) {         wanted.add(field);     } } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -