您身边的网站建设专家
成功案例

【建站服务】南昌做网站/制作网站/搭建网站/设计网站/开发网站-网站服务一站式-域名申请

日期: 2022-09-21 04:11:43 浏览数:3


上往建站提供服务器空间服务商百度快照排名网站托管百度推广运营,致力于设计外包服务与源代码定制开发360推广搜狗推广,增加网站的能见度及访问量提升网络营销的效果,主营:网站公司,百度推广公司电话,官网搭建服务,网站服务企业排名,服务器空间,英文域名等业务,专业团队服务,效果好。


南昌做网站/制作网站/搭建网站/设计网站/开发网站-网站服务一站式

网站建设.png

假设,我们定义了某个 Annotaion,它的名称是 MyAnnotation,并且 MyAnnotation 被标注为 @Inherited。现在,某个类 Base 使用了

MyAnnotation,则 Base 具有了"具有了注解 MyAnnotation";现在,Sub 继承了 Base,由于 MyAnnotation 是 @Inherited的(具有继承性),所以,Sub 也 "具有了注解 MyAnnotation"。

@Inherited 的使用示例:

InheritableSon.java

import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Inherited;

/**
 * 自定义的Annotation。
 */

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface Inheritable
{
}

@Inheritable
class InheritableFather
{
    public InheritableFather() {
        // InheritableBase是否具有 Inheritable Annotation
        System.out.println("InheritableFat



    public InheritableFather() {

        // InheritableBase是否具有 Inheritable Annotation

        System.out.println("InheritableFather:"+InheritableFather.class.isAnnotationPresent(Inheritable.class));

    }

}


/**

 * InheritableSon 类只是继承于 InheritableFather,

 */

public class InheritableSon extends InheritableFather

{

    public InheritableSon() {

        super();    // 调用父类的构造函数

        // InheritableSon类是否具有 Inheritable Annotation

        System.out.println("InheritableSon:"+InheritableSon.class.isAnnotationPresent(Inheritable.class));

    }

   

    public static void main(String[] args)

    {

        InheritableSon is = new InheritableSon();

    }

}

运行结果:


InheritableFather:true

InheritableSon:true

现在,我们对 InheritableSon.java 进行修改:注释掉 "Inheritable 的 @Inherited 注解"。


InheritableSon.java

import java.lang.annotation.Target;

import java.lang.annotation.ElementType;

import java.lang.annotation.Retention;

import java.lang.annotation.RetentionPolicy;

import java.lang.annotation.Inherited;


/**

 * 自定义的Annotation。

 */

@Target(ElementType.TYPE)

@Retention(RetentionPolicy.RUNTIME)

//@Inherited

@interface Inheritable

{

}


@Inheritable

class InheritableFather

{

    public InheritableFather() {

        // InheritableBase是否具有 Inheritable Annotation

        System.out.println("InheritableFather:"+InheritableFather.class.isAnnotationPresent(Inheritable.class));


南昌做网站/制作网站/搭建网站/设计网站/开发网站-网站服务一站式


上往建站提供搭建网站域名注册官网备案服务网店详情页设计企业网店专业网络店铺管理运营全托管公司咨询电话,服务器空间,微信公众号托管网页美工排版,致力于域名申请竞价托管软文推广全网营销,提供标准级专业技术保障,了却后顾之忧,主营:虚拟主机网站推广百度竞价托管网站建设上网建站推广服务网络公司有哪些等业务,专业团队服务,效果好。

服务热线:400-111-6878 手机微信同号:18118153152(各城市商务人员可上门服务)


全国咨询热线:400-111-6878

地址:全国各地都有驻点商务

Copyright © 2021 通陆科技

网站建设上往建站