• 类的类别顶级类,内嵌类、内部类、本地类、内名类


    // There are five kinds of classes (or interfaces):
    // a) Top level classes
    // b) Nested classes (static member classes)
    // c) Inner classes (non-static member classes)
    // d) Local classes (named classes declared within a method)
    // e) Anonymous classes

    在看自动装配类的如何扫描拥有的注解的时候,发现了这一段,对类进行了区分,包括 顶级类,内嵌类(静态成员类)、内部类(非静态成员类)、本地类(使用方法名声明的类)、内名类
    源码位置

    public final class Class<T> implements java.io.Serializable,
                                  GenericDeclaration,
                                  Type,
                                  AnnotatedElement {
        @CallerSensitive
        public Class<?> getEnclosingClass() throws SecurityException {
            // There are five kinds of classes (or interfaces):
            // a) Top level classes
            // b) Nested classes (static member classes)
            // c) Inner classes (non-static member classes)
            // d) Local classes (named classes declared within a method)
            // e) Anonymous classes
    
    
            // JVM Spec 4.8.6: A class must have an EnclosingMethod
            // attribute if and only if it is a local class or an
            // anonymous class.
            EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();
            Class<?> enclosingCandidate;
    
            if (enclosingInfo == null) {
                // This is a top level or a nested class or an inner class (a, b, or c)
                enclosingCandidate = getDeclaringClass();
            } else {
                Class<?> enclosingClass = enclosingInfo.getEnclosingClass();
                // This is a local class or an anonymous class (d or e)
                if (enclosingClass == this || enclosingClass == null)
                    throw new InternalError("Malformed enclosing method information");
                else
                    enclosingCandidate = enclosingClass;
            }
    
            if (enclosingCandidate != null)
                enclosingCandidate.checkPackageAccess(
                        ClassLoader.getClassLoader(Reflection.getCallerClass()), true);
            return enclosingCandidate;
        }
    }
    
  • 相关阅读:
    android开发 软键盘出现后 防止EditText控件遮挡 总体平移UI
    jQuery中this与$(this)的差别
    纯手写wcf代码,wcf入门,wcf基础教程
    JavaScript权威指南第01章 JavaScript 概述
    Python
    微信支付界面中文乱码问题
    EasyUI基础入门之Pagination(分页)
    Maximum Subarray
    CF1063F String Journey
    排序
  • 原文地址:https://www.cnblogs.com/nangonghui/p/16280937.html
Copyright © 2020-2023  润新知