元数据
元数据:数据的数据,比如Class就是一种元数据
可以看到顶层接口有两个:ClassMetadata
和AnnotatedTypeMetadata
注解上的注解,Spring
将其定义为元注解(meta-annotation
),如 @Component
标注在 @Service
上,@Component
就被称作为元注解。后面我们就将注解的注解称为元注解。
ClassMetadata:对Class
的抽象和适配
此接口的所有方法,都是获取class上的元素
public interface ClassMetadata {
/**
* Return the name of the underlying class.
*/
String getClassName();
/**
* Return whether the underlying class represents an interface.
*/
boolean isInterface();
/**
* Return whether the underlying class represents an annotation.
* @since 4.1
*/
boolean isAnnotation();
/**
* Return whether the underlying class is marked as abstract.
*/
boolean isAbstract();
/**
* // 是否允许创建 不是接口且不是抽象类 这里就返回true了
*
*/
boolean isConcrete();
/**
* Return whether the underlying class is marked as 'final'.
*/
boolean isFinal();
/**
* 是否是独立的(能够创建对象的) 比如是Class、或者内部类、静态内部类
*/
boolean isIndependent();
/**
* 是否有内部类
*/
boolean hasEnclosingClass();
/**
* Return the name of the enclosing class of the underlying class,
* or {@code null} if the underlying class is a top-level class.
*/
@Nullable
String getEnclosingClassName();
/**
* Return whether the underlying class has a super class.
*/
boolean hasSuperClass();
/**
* Return the name of the super class of the underlying class,
* or {@code null} if there is no super class defined.
*/
@Nullable
String getSuperClassName();
// 会把实现的所有接口名称都返回 具体依赖于Class#getSuperclass
String[] getInterfaceNames();
// 基于:Class#getDeclaredClasses 返回类中定义的公共、私有、保护的内部类
String[] getMemberClassNames();
}
继承树如下
StandardClassMetadata
基于Java标准的(Standard)反射实现元数据的获取
/*
* Copyright 2002-2017 the original author or auth