We all love annotations. Really, they're nice markers for your pointcuts, create the option to have cross cutting concerns easily (i.e. only log these marked fields, or mask these annotated fields when logging). However, we do need to be able to *get* to those annotations at runtime to inject those fancy tricks we have up our sleeve. In comes the beautiful google reflections library which allows us to scan the class files for annotations. Of course, we made those annotations available at runtime, right? If not, add @Retention(RetentionPolicy.RUNTIME) to the annotation ;) So, scanning at runtime done easy: Collection<URL> urls = ClasspathHelper.forPackage("nl.shopname.location.domain"); Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(urls).setScanners(new FieldAnnotationsScanner())); Set<Field> fieldsWithAnnotation = <reflections.getF...
This is a simple blog to help me remember those cool code snippets which I used. Either by copy, or by cobbling... I do not intend this to be read by people except for me and my bad mind.