2010년 9월 27일 월요일

SuppressWarnings value값 지정

Resources:
- http://knol.google.com/k/suppresswarnings-annotation-in-java#
- http://download.oracle.com/javase/tutorial/java/javaOO/annotations.html


SuppressWarnings 의 값들은 Java에서 제공하는 표준 값들과 Eclipse와 같은 IDE에서 자체적으로 정의한 값들이 있다.
SuppressWarnings의 값으로 지정하면 IDE에서 해당 Warning이 발견되면 Warning을 무시한다.

JDK에서 정의한 값들은 아래와 같다.

For example, Sun JDK 1.5 shows:

* all - suppress all warnings from this code
* deprecation - suppress warnings from using deprecated code
* unchecked - suppress warnings from an unchecked call or an unchecked cast
* fallthrough - suppress warnings if a switch falls through without finding a valid case (and no default)
* path -
* serial - suppress warnings if a Serializable class does not define a serialVersionUID
* finally - suppress warnings from return within a finally (which will ignore return with the try)


And Sun JDK 1.6 adds:

* cast
* divzero - suppress warnings if integer divide by zero is detected
* empty
* overrides
* none


Eclipse는 JDK에서 정의한 값을 포함하여 아래의 값들을 사용할 수 있다.

The Eclipse warning values for Eclipse 3.3 are documented in the JDT docs.

* all - suppress all warnings
* boxing - suppress warnings relative to boxing/unboxing operations
* cast - suppress warnings relative to cast operations
* dep-ann - suppress warnings relative to deprecated annotation
* deprecation - suppress warnings relative to deprecation
* fallthrough - suppress warnings relative to missing breaks in switch statements
* finally - suppress warnings relative to finally block that don't return
* hiding - suppress warnings relative to locals that hide variable
* incomplete-switch - suppress warnings relative to missing entries in a switch statement (enum case)
* nls - suppress warnings relative to non-nls string literals
* null - suppress warnings relative to null analysis
* restriction - suppress warnings relative to usage of discouraged or forbidden references
* serial - suppress warnings relative to missing serialVersionUID field for a serializable class
* static-access - suppress warnings relative to incorrect static access
* synthetic-access - suppress warnings relative to unoptimized access from inner classes
* unchecked - suppress warnings relative to unchecked operations
* unqualified-field-access - suppress warnings relative to field access unqualified
* unused - suppress warnings relative to unused code



Examples

An example of specifying a single warning:
@SuppressWarnings("unchecked")
public void methodWithScaryWarnings() {
List rawList = new ArrayList();
List stringList = (List)rawList;
}

An example of using two warnings:
@SuppressWarnings({"unchecked","deprecation"})
public void methodWithScaryWarnings() {
callDeprecatedMethod();
}

댓글 없음:

댓글 쓰기