This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 38045
    
  22
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: 24183
    
  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: 38045
    
  22
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: 38045
    
  22
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: 19655
    
  18

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

Joined: Oct 13, 2005
Posts: 38045
    
  22
There are lots of things the compiler allows . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @Deprecated
 
Similar Threads
Replace a deprecated getResources() in a servlet init
Parent: null:maven-eclipse-plugin:maven-plugin:2.8 of project
JDK1.2 Vs JDK1.3
JavaBeans
Question about Threads