I was studying the legacy API's in the Java's Collection Framework
and I learnt that classes such as Vector
and HashTable
have been superseded by ArrayList
and HashMap
.
However still they are NOT deprecated, and deemed as legacy when essentially, deprecation is applied to software features that are superseded and should be avoided, so, I am not sure when is a API deemed legacy and when it is deprecated.
From the official Sun glossary:
From the how-and-when to deprecate guide:
The
@Deprecated
annotation went a step further and warn of danger:References
Note that the official glossary does not define what "legacy" means. In all likelihood, it may be a term that Josh Bloch used without an exact definition. The implication, though, is always that a legacy class should never be used in new code, and better replacement exists.
Perhaps an old code using legacy but non-deprecated class requires no action, since for now at least, they aren't in danger of ceasing to exist in future version.
In contrast, deprecation explicitly warns that they may cease to exist, so action should be taken to migrate to the replacement.
Quotes from Effective Java 2nd Edition
For comparison on how these terms are used in context, these are quotes from the book where the word "deprecated" appears:
By contrast, these are the quotes where the word "legacy" appears:
These quotes were not carefully selected: they're ALL instances where the word "deprecated" and "legacy" appear in the book. Bloch's message is clear here:
Thread.stop
, are dangerous, and should never be used at all.wait/notify
can stay in legacy code, but should not be used in new code.My own subjective opinion
My interpretation is that deprecating something is admitting that it is a mistake, and was never good to begin with. On the other hand, classifying that something is a legacy is admitting that it was good enough in the past, but it has served its purpose and is no longer good enough for the present and the future.
The Deprecated annotation gives a formal definition of a deprecated API. I don't think that a formal definition for legacy classes exists. Both actually mean that the class shouldn't be used in new code.
Deprecation means that it's bad and shouldn't be used -
File.toURL()
is a prime example, since it doesn't create correct URLs from files with spaces in the path. It's simply not doing what it should, but since existing code might be using workarounds which would break if the bug was fixedLegacy just means that it's old and there are ways of doing something which are generally, but not necessarily, better.
Vector
is a good example - it is aList
implementation, but it's still got some ugly crap from the days before the Collections API (i.e.,List
) was designed. It is also synchronized, which means that you have to pay the synchronization fee even when using it in a single-threaded scenario (except for in some situations where the VM is clever).ArrayList
is better if you want an array-backed list implementation since it's unsynchronized, andCollections.synchronizedList
is more flexible when you want a synchronized list since it's a wrapper which can be used with all list implementations (linked lists, lists fromArrays.asList(T...)
, etc). However, if you do happen to want a synchronized, array-backed list implementation, thenVector
is fine.My interpretation is that Legacy code simply has newer counterparts that do the job better. It will, however, continue to receive bug fixes and other support. Deprecated code, on the other hand, is unsupported and won't receive dedicated bug fixes.
A common interpretation is that Deprecated means that it will be removed in the near future, and Legacy means that it will remain for backwards compatibility or other reasons.
Both mean that they shouldn't be used by new code.
In the case of the JDK even Deprecated code will remain, since backwards compatibility is very important for the Java JDK.
I have a suggestion - legacy refers to code that was written in the past, deprecated refers to the advice not to use it anymore. You can still use deprecated api, but you can't write legacy code, cuz you're writing it right now. Just IMHO