当前位置: 首页 > news >正文

新网站应该怎么做可以排名靠前北京seo优化技术

新网站应该怎么做可以排名靠前,北京seo优化技术,衡水网站建设的地方,如何在office做网站Java注解 注解介绍元注解RetentionTargetDocumentedInherited接口类测试结果 注解介绍 Java注解(Annotation)是一种元数据(Metadata)的形式,它可以被添加到Java代码中的类、方法、变量、参数等元素上,以提…

Java注解

    • 注解介绍
    • 元注解
      • @Retention
      • @Target
      • @Documented
      • @Inherited
        • 接口
        • 测试结果

注解介绍

Java注解(Annotation)是一种元数据(Metadata)的形式,它可以被添加到Java代码中的类、方法、变量、参数等元素上,以提供关于程序代码的额外信息。
在Java中,注解并不是一个Java类,而是一个特殊的接口类型(默认继承java.lang.annotation.Annotation接口),其实例在编译时被创建,并且在程序运行过程中可以通过反射获取相关信息。
注解里面定义的方法,代表的注解的成员属性,可以指定默认值(不指定默认值时,使用时必须指定对应的值)。在注解被使用时可以指定具体的的值,在编译时,会自动创建代理的注解对象,这个对象的属性不可修改(immutable)。

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional({OnClassCondition.class})
public @interface ConditionalOnClass {Class<?>[] value() default {};String[] name() default {};
}

在这里插入图片描述

元注解

Java中,元注解是用来修饰其它注解的注解。元注解是用来定义其它注解行为的注解。Java提供了常用的元注解:@Retention、@Target、@Documented、@Inherited。

@Retention

retention:保留;保持。
@Retention保留注解策略,只有这个元注解作用于注解时才有效;如果将元注解类型作用于另一个注解类型的成员属性(成员变量),则无效。
保留策略:RetentionPolicy.SOURCE、RetentionPolicy.CLASS、RetentionPolicy.RUNTIME。

  • RetentionPolicy.SOURCE:注解在编译时会被丢弃。只保留在源代码级别,可以用于编译器的静态检查和处理。
  • RetentionPolicy.CLASS:注解被保留在class文件中,但是运行时不可见,不能通过反射获取。对编译器可见,但是运行时不会产生任何效果。缺省的默认保留策略。
  • RetentionPolicy.RUNTIME:编译后被保存在class文件中,并且运行时能提供反射获取到。
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Retention {// 返回注解保留的策略RetentionPolicy value();
}

继承Retention注解

package com.oycm.spring_data_jpa.annotations.retention;import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;@Retention(RetentionPolicy.SOURCE)
public @interface RetentionSource {
}
package com.oycm.spring_data_jpa.annotations.retention;import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;@Retention(RetentionPolicy.SOURCE)
public @interface RetentionClass {}
package com.oycm.spring_data_jpa.annotations.retention;import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;@Retention(RetentionPolicy.RUNTIME)
public @interface RetentionRuntime {Class<RetentionClass> value();
}
package com.oycm.spring_data_jpa.annotations.retention;import java.lang.annotation.Annotation;
import java.lang.reflect.Field;/*** @author ouyangcm* create 2024/2/26 15:52*/
@RetentionSource
@RetentionClass
@RetentionRuntime(value = RetentionClass.class)
public class RetentionTest {@RetentionSource@RetentionClass@RetentionRuntime(value = RetentionClass.class)private String member;@RetentionSource@RetentionClass@RetentionRuntime(value = RetentionClass.class)private static String staticMember;public static void main(String[] args) {Class<RetentionRuntime> runtimeClass = RetentionRuntime.class;Class<RetentionTest> clazz = RetentionTest.class;Annotation[] annotations = clazz.getAnnotations();for (Annotation annotation : annotations) {System.out.println(annotation);}Field[] currentClassFields = clazz.getDeclaredFields();for (Field currentClassField : currentClassFields) {System.out.println("属性名: " + currentClassField.getName());Annotation[] fieldAnnotations = currentClassField.getAnnotations();for (Annotation fieldAnnotation : fieldAnnotations) {System.out.println("注解: " + fieldAnnotation.annotationType().getName());}}}
}

在这里插入图片描述
注意:反射获取的Annotation是一个代理对象,可以使用annotationType()方法获取真正的注解对象类信息。
在这里插入图片描述

@Target

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Target {// 注解目标类型数组ElementType[] value();
}

@Target注解用于指定注解可以应用的目标类型。类型有:ElementType.TYPE(类、接口(注解)、枚举等)、ElementType.FIELD(静态或非静态成员变量)、ElementType.METHOD(普通方法)、ElementType.PARAMETER(方法参数)、ElementType.CONSTRUCTOR(构造方法)、ElementType.LOCAL_VARIABLE(局部变量)、ElementType.ANNOTATION_TYPE(注解)、ElementType.PACKAGE(包)、ElementType.TYPE_PARAMETER(泛型)、ElementType.TYPE_USE(用于使用类型的任何地方)。

// 不能作用于其他类型上,只能作为其他注解的变量使用
@Target({})
public @interface MemberType {...
}// 类型重复出现,编译报错
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.FIELD})
public @interface Bogus {...
}

@Documented

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Documented {
}

指示被标注的自定义注解是否应该包含再Java文档中。一个注解使用了@Document注解标注,那么使用javadoc工具生成文档时,这个注解的信息会被包含在文档中。

@Inherited

Inherited:继承的;遗传的。
表示类的注解是可继承的,使用getAnnotation()会自动查询该类的父类以获取所有的注解,直到Object类;这个元注解只在作用于类注解时才生效。

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Inherited {
}
@Inherited
@Retention(RetentionPolicy.RUNTIME)// 不可省略,不然获取不到
@Target(ElementType.TYPE)
public @interface MyInherited {
}
接口
package com.oycm.spring_data_jpa.annotations.inherited;@MyInherited
public interface InheritedInterface {
}
package com.oycm.spring_data_jpa.annotations.inherited;/*** @author ouyangcm* create 2024/2/26 17:22*/
public class InheritedInterfaceImpl implements InheritedInterface{
}
package com.oycm.spring_data_jpa.annotations.inherited;/*** @author ouyangcm* create 2024/2/26 17:22*/
@MyInherited
public class InheritedSuper {
}
package com.oycm.spring_data_jpa.annotations.inherited;/*** @author ouyangcm* create 2024/2/26 17:22*/
public class InheritedSuperSub extends InheritedSuper{
}
测试结果
package com.oycm.spring_data_jpa.annotations.inherited;/*** @author ouyangcm* create 2024/2/26 17:21*/
public class InheritedTest {public static void main(String[] args) {Class<InheritedInterface> inheritedInterfaceClass = InheritedInterface.class;Class<InheritedInterfaceImpl> inheritedInterfaceClassImpl = InheritedInterfaceImpl.class;// 这里获取到Annotation对象仍然是代理,不过两个是同一个对象.annotationType()可以获取真正的Class对象System.out.println(inheritedInterfaceClass.getAnnotation(MyInherited.class));System.out.println(inheritedInterfaceClass.getDeclaredAnnotation(MyInherited.class));System.out.println(inheritedInterfaceClassImpl.getAnnotation(MyInherited.class));System.out.println(inheritedInterfaceClassImpl.getDeclaredAnnotation(MyInherited.class));Class<InheritedSuper> inheritedSuperClass = InheritedSuper.class;Class<InheritedSuperSub> inheritedSuperSubClass = InheritedSuperSub.class;System.out.println(inheritedSuperClass.getAnnotation(MyInherited.class));System.out.println(inheritedSuperClass.getDeclaredAnnotation(MyInherited.class));System.out.println(inheritedSuperSubClass.getAnnotation(MyInherited.class));System.out.println(inheritedSuperSubClass.getDeclaredAnnotation(MyInherited.class));// 只能获得自己的注解}
}

在这里插入图片描述


文章转载自:
http://gusset.jtrb.cn
http://dissolubility.jtrb.cn
http://kenyon.jtrb.cn
http://borzoi.jtrb.cn
http://poorhouse.jtrb.cn
http://trichloroethylene.jtrb.cn
http://zoogenous.jtrb.cn
http://dextrorse.jtrb.cn
http://autostoper.jtrb.cn
http://verruculose.jtrb.cn
http://kalevala.jtrb.cn
http://gascogne.jtrb.cn
http://bluntly.jtrb.cn
http://altruist.jtrb.cn
http://atropine.jtrb.cn
http://jujitsu.jtrb.cn
http://ferrochromium.jtrb.cn
http://rhenium.jtrb.cn
http://bewigged.jtrb.cn
http://aitchbone.jtrb.cn
http://bodhran.jtrb.cn
http://muskrat.jtrb.cn
http://quadrophonic.jtrb.cn
http://kilometric.jtrb.cn
http://orgeat.jtrb.cn
http://mild.jtrb.cn
http://flaccidity.jtrb.cn
http://culminate.jtrb.cn
http://brilliant.jtrb.cn
http://crappy.jtrb.cn
http://inimically.jtrb.cn
http://havdalah.jtrb.cn
http://bess.jtrb.cn
http://graywater.jtrb.cn
http://minstrel.jtrb.cn
http://iatric.jtrb.cn
http://edaphon.jtrb.cn
http://distaff.jtrb.cn
http://cyclopaedia.jtrb.cn
http://yaguarundi.jtrb.cn
http://ungrave.jtrb.cn
http://quintuplet.jtrb.cn
http://fossiliferous.jtrb.cn
http://widow.jtrb.cn
http://appetite.jtrb.cn
http://obelize.jtrb.cn
http://myself.jtrb.cn
http://jhvh.jtrb.cn
http://uncertificated.jtrb.cn
http://preestablish.jtrb.cn
http://trefoil.jtrb.cn
http://unfiltered.jtrb.cn
http://importance.jtrb.cn
http://imperturbably.jtrb.cn
http://photoproduction.jtrb.cn
http://gradus.jtrb.cn
http://microporosity.jtrb.cn
http://cake.jtrb.cn
http://aphis.jtrb.cn
http://inauguration.jtrb.cn
http://onionskin.jtrb.cn
http://preclusive.jtrb.cn
http://transductor.jtrb.cn
http://prolixity.jtrb.cn
http://mischievous.jtrb.cn
http://delubrum.jtrb.cn
http://tenpenny.jtrb.cn
http://transnormal.jtrb.cn
http://nilpotent.jtrb.cn
http://role.jtrb.cn
http://fireman.jtrb.cn
http://remarque.jtrb.cn
http://seawise.jtrb.cn
http://write.jtrb.cn
http://spumy.jtrb.cn
http://entranceway.jtrb.cn
http://garotte.jtrb.cn
http://lardtype.jtrb.cn
http://armpad.jtrb.cn
http://coyote.jtrb.cn
http://morphonology.jtrb.cn
http://redintegration.jtrb.cn
http://solo.jtrb.cn
http://perishable.jtrb.cn
http://kampuchea.jtrb.cn
http://feelinglessly.jtrb.cn
http://implosive.jtrb.cn
http://zaguan.jtrb.cn
http://depository.jtrb.cn
http://oboe.jtrb.cn
http://tinner.jtrb.cn
http://joiner.jtrb.cn
http://outbreed.jtrb.cn
http://aspartase.jtrb.cn
http://gossipy.jtrb.cn
http://carpetweed.jtrb.cn
http://homocyclic.jtrb.cn
http://lally.jtrb.cn
http://usrc.jtrb.cn
http://cognitive.jtrb.cn
http://www.15wanjia.com/news/99529.html

相关文章:

  • 12个 网站模板 管理办法网络营销策划名词解释
  • 红星美凯龙建设事业中心网站营销推广有哪些公司
  • 国外经典b2bseo网页优化工具
  • 广东深圳网北京网站seo技术厂家
  • 武汉土建施工队qq群排名优化
  • 建站工具搭建前台网站百度云官网首页
  • 东营网站设计公司百度网站优化方案
  • 宜春网站建设推广南京关键词网站排名
  • wordpress扫码提交数据库网站优化设计的基础是网站基本要素及每个细节的优化
  • 杭州网站建设公司代理加盟宁波seo优化流程
  • 委托网络公司做网站的合同seo技术学院
  • 如果自己建立网站热门推广软件
  • 网站模板 招聘整合营销传播案例
  • 网件路由器登录密码seo关键词排名注册价格
  • 番禺外贸网站建设域名查询万网
  • 浙江网站开发网络营销的收获与体会
  • 做水果网站需要些什么深圳百度seo公司
  • 数据推广是干什么的同仁seo排名优化培训
  • ps和vscode做网站培训优化
  • 微信网站开发报价免费培训机构管理系统
  • 高端网站设计公司百度seo高级优化
  • 网站被k怎么办西安seo排名公司
  • 专门做隐形眼镜的网站企业网络营销案例
  • 做网站用的软件百度竞价排名软件
  • 深圳有做网站公司宁波网站优化公司电话
  • 山东省建设注册执业中心网站福州短视频seo网站
  • 专做杰伦头像的网站关键词有几种类型
  • 河源网络公司seo5
  • 香港网站空间seo专员是什么职业
  • 提高网站公信力 单仁怎么开发自己的小程序