12/29/2008

Annotation

Annotation is something like notes in a program.
JDK 5.0 or any later version supports annortaton.
See Annotation on java.sun.com

@Override
If the method is not properly overridden, then a compile error occurs.

class Super {
    void func(){
        System.out.println("Super");
    }
}
class Sub extends Super {
    @Override
    int func() {
        System.out.println("Sub");
    }
}

___________

@Deprecated
Warning of a deprecated method.

public static void main(String[] args) {
    func();
    }
    @Deprecated
    static void func() { }
}
___________

@SuppressWarnings("deprecation")
Suppresses the warning of a deprecated method.

@SuppressWarnings("fallthrough")
Suppresses the warning of the fall-through in a switch statement

@SuppressWarnings("finally")
Suppresses the warning that a finally block is not properly finished

@SuppressWarnings("serial")
Suppresses the warning that a serialVersionUID is not defined

When you supress more than one warning, write like this:
@SuppressWarnings({"deprecation", "finally"})