Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

@Deprecated class method  RSS feed

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find sometimes after I upgrade jdk or library,  some codes are no longer supported and compiling gives error since some methods or classes become deprecated as of certain new version of jdk or library.  In this case, if we use @Deprecated to annotate the class, method, etc, the compiling passes.  Question --- Why compiling passes with @Deprecated when the new jdk or library no longer has that class or method ?  Is it because when you put @Deprecated compiler automatically goes back to older version to check if it works with older version ?  Finally, does this mean this class/method can still be used (assuming it compiles with @Deprecated) ?
 
Ranch Hand
Posts: 73
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

This thread from the ranch is related to your question:

https://coderanch.com/t/683016/java/Deprecation-Java
 
Linwood Hayes
Ranch Hand
Posts: 110
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mano Ag wrote:
Hi,

This thread from the ranch is related to your question:

https://coderanch.com/t/683016/java/Deprecation-Java



That link was a joyful discussion about why developers still using deprecated stuff.   Not directly answering my questions though.
 
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Linwood Hayes wrote:I find sometimes after I upgrade jdk or library,  some codes are no longer supported and compiling gives error since some methods or classes become deprecated as of certain new version of jdk or library.  In this case, if we use @Deprecated to annotate the class, method, etc, the compiling passes.  Question --- Why compiling passes with @Deprecated when the new jdk or library no longer has that class or method ?  Is it because when you put @Deprecated compiler automatically goes back to older version to check if it works with older version ?



No, the compiler does not go looking for older versions of a JDK or library when it finds a deprecated method or class being used in your code. If you're asking about the JDK, a method or class which is deprecated has not been removed. It's still in the JDK and it can still be used, you'll just get a nagging warning message about it. Oracle (and Sun before it) has never removed any deprecated methods. For other libraries, the managers may remove a deprecated method or class when releasing a newer version of the library. In that case, trying to use the old deprecated method or class in your code will just result in a compiler error. The method or class just isn't there so the compiler can't find it.

I hope this helps -- your question reads as if you think you can change the JDK by annotating a class which isn't there and fix a problem.
 
Marshal
Posts: 59711
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, deprecation doesn't make the compiler go back to an earlier version. The @Deprecated annotation causes the compiler to issue a warning whose details can be viewed with an -Xlint option. It doesn't prevent compilation. It would be disastrous to go back to JDK1.0 because you wanted to use Thread#stop() and it wasn't deprecated people didn't realise how bad it was in the days of JDK1.0.
Deprecation seems to have been tightened up in Java9; the @Deprecated annotation gains two fields, one of them telling users that the deprecated feature may be removed altogether. Not certain, but I think that will mean that feature will be unavailable in new code, but old previously compiled .class files will still be usable. Lots of things were deprecated in Java8, including this well‑known method and several constructors similar to this one. Actually most people had stopped using those features before they were deprecated.
 
Linwood Hayes
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.  I found it is similar to third party library.  If I upgrade to higher version it gives compiler error.  Then I added @Deprecated, it just compiles but added an annoying cross-line for the class/method.  But I think it doesn't affect the functionality, right ?
 
Rancher
Posts: 3595
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you upgrade a third party library that has removed a method, then there's nothing you can mark in your code to magically get it to compile.

So I'm not sure what your actual issue is, but simply adding @Deprecated to something doesn't work won't recreate a missing method.
Maybe if you posted an example?
 
Campbell Ritchie
Marshal
Posts: 59711
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain more about how you got the compiler error.
 
Sheriff
Posts: 12195
199
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's probably your IDE that's trying to watch your back and force you to fix deprecation warnings. If you compile from the command line, javac will normally give you a warning message but will still compile any valid code.

You can also annotate methods that contain calls to deprecated methods with @SuppressWarnings("deprecation") -- this will force your IDE to stop nagging you or stopping you from getting on with it. There are occasions when it's fine to do that but you normally want to read the API documentation and replace the deprecated method call with its recommended alternative, if there is one. Help your IDE help you.

For example, the API documentation for the java.util.Time(int, int, int) constructor includes this recommendation:

Deprecated. Use the constructor that takes a milliseconds value in place of this constructor

 
Bartender
Posts: 19657
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:It's probably your IDE that's trying to watch your back and force you to fix deprecation warnings. If you compile from the command line, javac will normally give you a warning message but will still compile any valid code.



It is, and the IDE will normally compile as well, although I think Eclipse has an option to be more insistent.

The point of deprecation, as I probably said in the previously-referenced thread is to avoid situations where you get paged in the middle of the night, need to make a 1-line change to a critical production system, but first have to re-install an antique OS, patch it, install an antique IDE (I'm looking at YOU, Visual Studio!), patch IT, make the fix, and compile it, thus expanding a 5-minute repair job into a 3-hour one. And that's being optimistic, since I've always had the resources and ability to actually install obsolete software myself instead of having to chase down and wait on external OS support personnel.

Deprecation gives you the ability to use something you shouldn't until you can go back and make a proper repair with proper techniques and proper testing. And to remind you when you have to touch the code later. Be grateful. The Good Old Days were not that good.
 
Junilu Lacar
Sheriff
Posts: 12195
199
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:Be grateful. The Good Old Days were not that good.


Ah, but it's fun to wax nostalgic about the simpler times when physical hardware constraints kept us from winding too much rope around our necks and complexity could be kept within the bounds of a floppy disk.
 
Paul Clapham
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:So I'm not sure what your actual issue is, but simply adding @Deprecated to something doesn't work won't recreate a missing method.



It's even harder to add @Deprecated to something which doesn't exist. So I'm not sure what that was about either.
 
Tim Holloway
Bartender
Posts: 19657
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Tim Holloway wrote:Be grateful. The Good Old Days were not that good.


Ah, but it's fun to wax nostalgic about the simpler times when physical hardware constraints kept us from winding too much rope around our necks and complexity could be kept within the bounds of a floppy disk.



Well, actually, the episode I was referring to was in the days of 40GB hard drives and Windows NT. But whatever,

The mainframe I also used could still do builds on programs written in the 1960s. But IBM understood the need for long-term stability long before Java was invented.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!