• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@Deprecated

 
Kalyan Anand
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The @Deprecated tag can target a class, a field, a constructor or a method.
 
Kalyan Anand
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes but why did not they specify that in Target for this annotation type ?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Kalyan Anand
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A field yes. The others: stop being silly
 
Kalyan Anand
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annotations can be used on any kind of class member. Probably constructors too, but I haven't tried.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots of things the compiler allows . . .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic