• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question regarding annotation

 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My online study course is taking me through a section on annotations. This is causing a lot of confusion for me and I have whittled a myriad of my "wonderings" down to one question that may help break the logjam loose.

If someone could, please, tell me: Why use @Deprecated to indicate that a method is invalid and should no longer be use?

If you have access to the source and the permissions required to edit it.... why not remove it?

If it should no longer be used then it would seem that it would be a case to take it clean out of the source so it can't be compiled.

The only thing that @Deprecated seems to allow is..... leaving the method source in.... but disallowing it's use.

What am I not seeing?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe the method has been around for 5 years, and is already imbedded in millions of lines of legacy code. You don't want anybody else to use it in NEW development, but you sure as heck don't want to break all that old stuff.

you can have a project to take it out of the legacy code as you work on other things (i.e. you were in the file anyway, so you can correct it as you go), but you need to leave it there until all that is done.
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree while I'm developing code I use the @depreciated annotation in my code for saying don't use this code again. Mostly I'm in a hurry so I don't want to change al my code that uses the old methods or classes. After that I will clean my code where the use of the old method is removed and then I delete the method. Eclipse has a nice warning for this.

For customers I will log a warning that within a year the method will be removed. This gives other developers the time to adjust their code and I can read in the logs that they still use the old one.
[ July 09, 2007: Message edited by: Remko Strating ]
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the speedy responses.

I guess where it really confuses me is that, once you make it deprecated, the compiler flat won't let you reference it anymore so you have to change your code anyway. At least that is the picture I get.

Now.....be gentle with me, I'm trying to think outside the box....

Is it that, if I annotate a method as being deprecated and rebuild just that class.... the existing classes can still refer to it even though it is deprecated BUT any attempts to compile classes against it will fail?

I'm not sure that I am clearly stating what I am thinking... does the deprecation allow the existing (as in not recompiled) classes to work with the deprecated method BUT whenever someone attempts to recompile one of those classes that references the deprecated method, the compilation will fail??
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i could be wrong, since i haven't used it or tried it in a long time, but are you SURE it won't let you compile?

sometimes it just give warnings that LOOK like errors, but i couldn't say for sure.
 
Remko Strating
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My experience until now is that it compiles but generates a warning like depreciated methods.

If your experience is different can you give an example.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remko Strating, I trust you are using @Deprecated, not depreciated. The standard Java compilers are even more pedantic than me! They will notice the spelling error and not take any action! And a capital D.
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, to be honest, I have not coded anything yet, I am just studying these in an online training course and the current section happens to be introducing annotations. In an example that they cite, they claim that the code referencing the deprecated method will not compile.... but, as I say, I have not personally tried anything.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic