一、@SuppressLint用法
在使用Fragment时,当需要创建一个带有构造函数的Fragment,一般情况下编译无法通过
@SuppressLint("ValidFragment")
public class ReplayFragment extends Fragment{
public ReplayFragment(Context context){
getChannelInfoFileData(context);
}
加了@SuppressLint("ValidFragment")才可以编译通过
二、@SuppressWarings用法
示例1——抑制单类型的警告:
@SuppressWarnings("unchecked")publicvoidaddItems(String item){
@SuppressWarnings("rawtypes")
List items=newArrayList();
items.add(item);
}
示例2——抑制多类型的警告:
@SuppressWarnings(value={"unchecked","rawtypes"})publicvoidaddItems(String item){
List items=newArrayList();
items.add(item);
}
示例3——抑制所有类型的警告:
@SuppressWarnings("all")publicvoidaddItems(String item){
List items=newArrayList();
items.add(item);
}
三、注解目标
通过@SuppressWarnings的源码可知,其注解目标为类、字段、函数、函数入参、构造函数和函数的局部变量。