Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:55:02+00:00 2026-06-07T19:55:02+00:00

Scenario: Java 1.6 class Animal { private String name; … public String getName() {

  • 0

Scenario:
Java 1.6

class Animal { 
    private String name; 
    ...  
    public String getName() { return name; }  
    ...
}

class CatDog extends Animal {
    private String dogName;
    private String catName;
    ...
    public String getDogName() { return dogName; }
    public String getCatName() { return catName; }
    public String[] getNames() { return new String[]{ catName, dogName }; }
    ...
    public String getName() { return "ERROR! DO NOT USE ME"; }
}

Problem:
getName doesn’t make sense and shouldn’t be used in this example. I’m reading about @Deprecated annotation. Is there a more appropriate annotation method?

Questions:
A) Is it possible to force an error when this function is used (before runtime)?
B) Is there a way to display a customized warning/error message for the annotation method I will use? Ideally when the user is hovering over deprecated/error function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:55:03+00:00Added an answer on June 7, 2026 at 7:55 pm

    Generally, you use @Deprecated for methods that have been made obsolete by a newer version of your software, but which you’re keeping around for API compatibility with code that depends on the old version. I’m not sure if it’s exactly the best tag to use in this scenario, because getName is still being actively used by other subclasses of Animal, but it will certainly alert users of the CatDog class that they shouldn’t call that method.

    If you want to cause an error at compile time when that function is used, you can change your compiler options to consider use of @Deprecated methods to be an error instead of a warning. Of course, you can’t guarantee that everyone who uses your library will set this option, and there’s no way I know of to force a compile error just based on the language specification. Removing the method from CatDog will still allow clients to call it, since the client will just be invoking the default implementation from the superclass Animal (which presumably you still want to include that method).

    It is certainly possible, however, to display a custom message when the user hovers over the deprecated method. The Javadoc @deprecated tag allows you to specify an explanation of why a method was deprecated, and it will pop up instead of the usual description of the method when the user hovers over the method in an IDE like Eclipse. It would look like this:

    /**
     * 
     * @deprecated Do not use this method!
     */
     @Deprecated
     public String getName() {
         throw new UnsupportedOperationException();
     }
    

    (Note that you can make your implementation of the method throw an exception to guarantee that if the user didn’t notice the @Deprecated tag at compile time, they’ll definitely notice it at runtime).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HelloTag.Java public class HelloTag extends SimpleTagSupport { @Override public void doTag() throws JspException, IOException
Scenario A.java-----------after erasure-------->M.class Scenario B.java-----------after erasure-------->M.class Then why A is illegal and B is
Consider the following scenario: class A<T> {} class B extends A<Integer> {} How can
Java lets you create an entirely new subtype of Throwable , e.g: public class
The Scenario is: Object anObj=7; Object anotherObject=7.77; Class aClass=Class.forName(java.lang.Integer); Class anotherClass=Class.forName(java.lang.Double); I want to
In Java, it is very easy to code the following design: public abstract class
I have a question regarding the LinkedList class in Java. I have a scenario
I am trying to send the events from one Java class to Activity. Scenario
I have a comparator class in Java to compare Map entries: public class ScoreComp
I have the following scenario : Class A{ private List<Long> longList; //getter and setter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.