个人做网站要缴税,什么是品牌,货源网站 源码,海事网站服务平台前些天发现了一个巨牛的人工智能学习网站#xff0c;通俗易懂#xff0c;风趣幽默#xff0c;忍不住分享一下给大家。点击跳转到教程。
Target#xff1a; Target说明了Annotation所修饰的对象范围#xff1a;Annotation可被用于 packages、types#xff08;类、接口、枚…前些天发现了一个巨牛的人工智能学习网站通俗易懂风趣幽默忍不住分享一下给大家。点击跳转到教程。
Target Target说明了Annotation所修饰的对象范围Annotation可被用于 packages、types类、接口、枚举、Annotation类型、类型成员方法、构造方法、成员变量、枚举值、方法参数和本地变量如循环变量、catch参数。在Annotation类型的声明中使用了target可更加明晰其修饰的目标。 作用用于描述注解的使用范围即被描述的注解可以用在什么地方 取值(ElementType)有
public enum ElementType {/**用于描述类、接口(包括注解类型) 或enum声明 Class, interface (including annotation type), or enum declaration */TYPE,/** 用于描述域 Field declaration (includes enum constants) */FIELD,/**用于描述方法 Method declaration */METHOD,/**用于描述参数 Formal parameter declaration */PARAMETER,/**用于描述构造器 Constructor declaration */CONSTRUCTOR,/**用于描述局部变量 Local variable declaration */LOCAL_VARIABLE,/** Annotation type declaration */ANNOTATION_TYPE,/**用于描述包 Package declaration */PACKAGE,/*** 用来标注类型参数 Type parameter declaration* since 1.8*/TYPE_PARAMETER,/***能标注任何类型名称 Use of a type* since 1.8*/TYPE_USE 1 ElementType.TYPE_PARAMETER(Type parameter declaration) 用来标注类型参数 栗子如下
Target(ElementType.TYPE_PARAMETER)Retention(RetentionPolicy.RUNTIME)public interface TypeParameterAnnotation {}// 如下是该注解的使用例子public class TypeParameterClassTypeParameterAnnotation T {public TypeParameterAnnotation U T foo(T t) {return null;} }
ElementType.TYPE_USE(Use of a type) 能标注任何类型名称包括上面这个ElementType.TYPE_PARAMETER的栗子如下
public class TestTypeUse {Target(ElementType.TYPE_USE)Retention(RetentionPolicy.RUNTIME)public interface TypeUseAnnotation {}public static TypeUseAnnotation class TypeUseClassTypeUseAnnotation T extends TypeUseAnnotation Object {public void foo(TypeUseAnnotation T t) throws TypeUseAnnotation Exception {}}// 如下注解的使用都是合法的SuppressWarnings({ rawtypes, unused, resource })public static void main(String[] args) throws Exception {TypeUseClassTypeUseAnnotation String typeUseClass new TypeUseAnnotation TypeUseClass();typeUseClass.foo();ListTypeUseAnnotation Comparable list1 new ArrayList();List? extends Comparable list2 new ArrayListTypeUseAnnotation Comparable();TypeUseAnnotation String text (TypeUseAnnotation String)new Object();java.util. TypeUseAnnotation Scanner console new java.util.TypeUseAnnotation Scanner(System.in);}}