tags:

views:

79

answers:

4

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?

+2  A: 

No there is not, as JavaDoc is a comment and as such not available at runtime.

Thomas Lötzer
A: 

annotations are available since version 1.5, so that is not possible for 1.4 and previous

chburd
+3  A: 

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.

Bozho
+1  A: 

The @deprecated tag is only used by the compiler but not put in the compiled java byte code, so you cannot detect it after compilation.

What is it you want to do?

Thorbjørn Ravn Andersen