| Author |
@Deprecated
|
Kalyan Anand
Ranch Hand
Joined: Feb 07, 2007
Posts: 194
|
|
|
The @Deprecated annotation doesn't have a Target on it on the java doc. As the target can be anything contructor, field, what ever why did not they mention that @Deprecated Targets class or a method ?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32649
|
|
|
The @Deprecated tag can target a class, a field, a constructor or a method.
|
 |
Kalyan Anand
Ranch Hand
Joined: Feb 07, 2007
Posts: 194
|
|
|
Yes but why did not they specify that in Target for this annotation type ?
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24051
|
|
From the javadoc for the @Target meta-annotation:
Indicates the kinds of program element to which an annotation type is applicable. If a Target meta-annotation is not present on an annotation type declaration, the declared type may be used on any program element.
So does that answer your question? Since anything can be deprecated, there's no need for @Target (the purpose of which is to restrict the applicability of an annotation type.)
|
[Jess in Action][AskingGoodQuestions]
|
 |
Kalyan Anand
Ranch Hand
Joined: Feb 07, 2007
Posts: 194
|
|
Since anything can be deprecated...
Can I deprecate a field or a local variable or a parameter ? [ September 29, 2008: Message edited by: Santhosh Jali ]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32649
|
|
A field yes. The others: stop being silly
|
 |
Kalyan Anand
Ranch Hand
Joined: Feb 07, 2007
Posts: 194
|
|
Originally posted by Campbell Ritchie: A field yes. The others: stop being silly
Then I think they should have set the Target on the Deprecated annotation as I cannot use the Deprecated annotation on all kinds of elements. What do you think ?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32649
|
|
|
Annotations can be used on any kind of class member. Probably constructors too, but I haven't tried.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Originally posted by Campbell Ritchie: A field yes. The others: stop being silly
Actually, you can make local variables and parameters deprecated using @Deprecated. It doesn't make any sense of course, but the compiler allows it.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32649
|
|
There are lots of things the compiler allows . . .
|
 |
 |
|
|
subject: @Deprecated
|
|
|