Your annotation marks the OLD_PATH field as deprecated, not the string "old_path" . In a migrateProperty call migrateProperty you pass a string, not a field. Thus, the method does not know the field where the value comes from, and cannot check it for annotations.
In the annotation, you indicate something about Java elements such as classes, fields, variables, methods. You cannot annotate objects, such as strings.
The article you are referencing talks about annotating formal parameters. Again, this is a parameter that is annotated, not an argument (value passed). If you put @Something in a method parameter, that parameter will always be annotated, regardless of the value that the calling object passes to this method.
What you can do, but I'm not sure if this is what you want - this is the following:
@Deprecated private static final String OLD_PATH = "old_path"; private static final String NEW_PATH = "new_path"; public load(Node node){ migrateProperty(node, getClass().getDeclaredField("OLD_PATH"), getClass().getDeclaredField("NEW_PATH") );
In this case, you are really passing a field, not a value.
source share