How can I tell at runtime that a Java 1.4 type or member is deprecated?

deprecated, java

Solution

You can't make such a check on javadoc tags. Well, you can, if you distribute your source code, load the source file and parse it for the `@deprecated` tag, but this is not preferable.

The pre-Java5 way of indicating something is by using a marker interface. You can define your own:

public interface Deprecated {
}

and make deprecated classes implement it. You cannot use it on methods, of course.

public final class Test implements Deprecated

And then check whether `Deprecated.class.isAssignableFrom(Test.class)`.

But deprecation is a purely indicative notion and should not be used at run-time to differentiate behaviour.

Problem

In Java 6 I can use a technique like this: ``` @Deprecated public final class Test { public static void main(String[] args) { System.out.println(Test.class.isAnnotationPresent(Deprecated.class)); } } ``` to decide if a type is deprecated. Is there any way at all to do this in 1.4 with the old style (Javadoc-based) deprecation?

Original source