views:

77

answers:

2
@Deprecated public class Betamax { ... }

In the above example, what effect does the @Deprecated have? Is it purely documentation? Or does it change something about how the compiler treats this class?

+2  A: 

The compiler enforces (as in checks and croaks on) some annotations (like @Override).

But the most useful part is that libraries can provide their own annotations (like @Entity or @PersistenceAware), of which the Java language (JDK core) does not know anything. This is kind of like adding domain-specific syntactic sugar right into the language.

@Deprecated is for documentation. It also creates compiler warnings when you use a deprecated method (or class), just like the old JavaDoc @deprecated tag.

Thilo
+1  A: 

Purely for documentation purposes.

If you mark something as deprecated then you indicate to a user via the generated Javadoc that this method/class should not be used, e.g.

Date(int year, int month, int date): Deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date) or GregorianCalendar(year + 1900, month, date).

If you mark something as deprecated it's good practice to indicate to a user what they should use in place of this method.

Jon