Annotations and Eclipse

One of the mistakes I frequently make when I create annotations is to forget to make them accessible at runtime.

Here’s an example of an annotation that can be reflected at runtime.

package ca.intelliware.example;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;

public @interface MyAnnotation {
	String value();

Usually I forget to add the @Retention to the class and I discover the problem, later, when I’m trying to reflect some code looking for a particular annotation.

Recently, I’ve noticed an annoying bug in Eclipse (at least in version 3.1.0): if I change my annotation to add the @Retention, Eclipse doesn’t properly rebuild classes that use my annotation. Those classes still behave as if the annotation isn’t visible at runtime. I have to rebuild my whole project to fix the problem.

It's only fair to share...
Share on Facebook
Tweet about this on Twitter
Share on LinkedIn

Leave a Reply