获取类的接口,所在的包,注解

复制代码
package com.liu.test03;

import java.lang.annotation.Annotation;

/**
 * @author : liu
 * 日期:17:03:17
 * 描述:IntelliJ IDEA
 * 版本:1.0
 */
public class Test04 {
    //这是一个main方法:是程序的入口
    public static void main(String[] args) {
        Class cls = Student.class;
        //获取运行时类的接口
        Class[] interfaces = cls.getInterfaces();
        for (Class s:interfaces
             ) {
            System.out.println(s);
        }
        //得到父类的接口
        //先得到父类的字节码信息
        Class superclass = cls.getSuperclass();
        //
        //得到父类的接口
        Class[] interfaces1 = superclass.getInterfaces();
        for (Class c: interfaces1
             ) {
            System.out.println(c);
        }
        //获取运行时类所在的包
        Package aPackage = cls.getPackage();
        System.out.println(aPackage);
        String name = aPackage.getName();
        System.out.println(name);
        //获取运行时类的注解:
        Annotation[] annotations = cls.getAnnotations();
        for (Annotation a:annotations
             ) {
            System.out.println(a);
        }
    }
}
复制代码

 

posted @   爱的加勒比  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示