Posted on 2011-10-07 15:05
leekiang 阅读(502)
评论(0) 编辑 收藏 所属分类:
java
1,SuppressWarnings的作用是抑制编译器产生警告信息。
@SuppressWarnings("unused")
@SuppressWarnings("unchecked")
eclipse支持的
SuppressWarning
的值如下,其他开发工具略有差异。
- all to suppress all warnings
- boxing to suppress warnings relative to boxing/unboxing operations
- cast to suppress warnings relative to cast operations
- dep-ann to suppress warnings relative to deprecated annotation
- deprecation to suppress warnings relative to deprecation
- fallthrough to suppress warnings relative to missing breaks in switch statements
- finally to suppress warnings relative to finally block that don't return
- hiding to suppress warnings relative to locals that hide variable
- incomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case)
- nls to suppress warnings relative to non-nls string literals
- null to suppress warnings relative to null analysis
- restriction to suppress warnings relative to usage of discouraged or forbidden references
- serial to suppress warnings relative to missing serialVersionUID field for a serializable class
- static-access to suppress warnings relative to incorrect static access
- synthetic-access to suppress warnings relative to unoptimized access from inner classes
- unchecked to suppress warnings relative to unchecked operations
- unqualified-field-access to suppress warnings relative to field access unqualified
- unused to suppress warnings relative to unused code
2,注解
注解是加入到java源代码中的一些描述性的数据,本身不能执行。可利用反射(当RetentionPolicy=
RUNTIME)或文本解析取得注解信息。
@Target,@Retention为元注解。
SuppressWarnings的源码如下:
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface SuppressWarnings {
String[] value();
}
package java.lang.annotation;
public enum RetentionPolicy {
/**
* Annotations are to be discarded by the compiler.
*/
SOURCE,
/**
* Annotations are to be recorded in the class file by the compiler
* but need not be retained by the VM at run time. This is the default
* behavior.
*/
CLASS,
/**
* Annotations are to be recorded in the class file by the compiler and
* retained by the VM at run time, so they may be read reflectively.
*
* @see java.lang.reflect.AnnotatedElement
*/
RUNTIME
}
package java.lang.annotation;
public enum ElementType {
TYPE,
FIELD,
METHOD,
PARAMETER,
CONSTRUCTOR,
LOCAL_VARIABLE,
ANNOTATION_TYPE,
PACKAGE
}
3,泛型
public <T> T testT(List<T> list){
T t =(T) list;
return t;
}
4,自动装箱
(AutoBoxing)
关于row type
http://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it/
http://www.blogjava.net/sevenguin/archive/2011/04/20/348628.html
转:J2SE5中的最新注释功能SuppressWarningshttp://wenku.baidu.com/view/9d20440f844769eae009edf2.html
实战篇:设计自己的AnnotationSupported Values for @SuppressWarnings