Java Function Annotation Help, use @Deprecated?

Viewed 39190

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.

4 Answers

After refactoring our User class, we could not remove userGuid property, because it was used by mobile apps. Therefore, I have marked it as deprecated. The good thing is dev tools such as IntellijIdea recognize it and shows the message.

public User {
    ...

    /**
     * @Deprecated userGuid equals to guid but SLB mobile app is using user_guid.
     * This is going to be removed in the future.
     */
    @Deprecated
    public String getUserGuid() {
        return guid;
    }
}

enter image description here

Related