Monday, September 29, 2003

@deprecated and backward compatibility

The @deprecated JavaDoc comment means a method or class is still usable, but you should not use it. It will gradually be phased out. Usually it means that a new method or class has been added to do the same thing. But exactly when is the old method or class removed, if ever? As it currently stands, @deprecated is an "idle threat". There's no timetable that support will ever be dropped. If a method or class was actually removed and code broke would that be okay? Would it be sufficient to say: "We told you back in JDK 1.1 that this was going to go away. You were sufficiently warned". That's impractical. Breaking running code is rarely, if ever, acceptable. So what happens? The JDK libraries get bigger over time and nothing ever goes away. That's the price we pay for backwards compatibility. At least @deprecated can trigger a warning that, for new code, you should consider other options but if the deprecation warning is in a sea of hundreds of other deprecation warnings, it's unlikely that you'll even notice it. Sigh.

Note: there's a discussion on this topic on the Sun Developer Network Forum.