This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes @Deprecated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "@Deprecated" Watch "@Deprecated" New topic
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: 44563
    
  34
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: 24193
    
  34

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: 44563
    
  34
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: 44563
    
  34
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: 20136
    
  30

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 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44563
    
  34
There are lots of things the compiler allows . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @Deprecated
 
It's not a secret anymore!