JavaSE---Class

1、概述

    Instances of the class {@code Class} represent classes and interfaces in a running Java application.

      Class 代表 Java运行时 中 类和接口的实例。

    An enum is a kind of class and an annotation is a kind of interface.

      枚举 是一种特殊的类,注解 是一种特殊的接口。

 

2、常用方法-Field

    2.1、getDeclaredFields()   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Returns an array of {@code Field} objects reflecting all the fields
     * declared by the class or interface represented by this
     * {@code Class} object.
This includes public, protected, default
     * (package) access, and private fields, but excludes inherited fields.
 
返回 在类或接口 声明的所有字段。
包括 publicprotecteddefaultprivate字段,排除 继承的字段。
 
If this {@code Class} object represents a class or interface with no
     * declared fields, then this method returns an array of length 0.
 
类或接口 中没有声明字段 ,将返回空数组。
 
If this {@code Class} object represents an array type, a primitive
     * type, or void, then this method returns an array of length 0.
 
如果是 数组类型 或 基本类型 或 void ,将返回 空数组。
 
The elements in the returned array are not sorted and are not in any
     * particular order.
 
返回的数组内容是 没有排序的。
 
 
@CallerSensitive
    public Field[] getDeclaredFields() throws SecurityException {
        checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
        return copyFields(privateGetDeclaredFields(false));
    }

 

    2.2、getFields()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Returns an array containing {@code Field} objects reflecting all
     * the accessible public fields of the class or interface represented by
     * this {@code Class} object.
 
返回 类或接口 中声明的 可访问的public字段。
 
 If this {@code Class} object represents a class or interface with no
     * no accessible public fields, then this method returns an array of length
     * 0.
 
如果 类或接口中 没有声明public 字段,将返回空数组。
 
If this {@code Class} object represents a class, then this method
     * returns the public fields of the class and of all its superclasses.
 
如果 Class对象 代表的是 类的,将返回 该类 和 它所有父类的 public字段。
 
If this {@code Class} object represents an interface, then this
     * method returns the fields of the interface and of all its
     * superinterfaces.
 
如果 Class对象 代表的是 接口的,将返回 该接口 和 它所有父接口的 public字段。
 
If this {@code Class} object represents an array type, a primitive
     * type, or void, then this method returns an array of length 0.
 
如果 代表的是数组 或 基本类型 或void ,将返回 空数组。
 
The elements in the returned array are not sorted and are not in any
     * particular order.
 
返回的数组 没有排序。
 
@CallerSensitive
    public Field[] getFields() throws SecurityException {
        checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
        return copyFields(privateGetPublicFields(null));
    }

  

3、常用方法-Constructor

    3.1、getConstructors()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Returns an array containing {@code Constructor} objects reflecting
     * all the public constructors of the class represented by this
     * {@code Class} object.
 
返回 声明在类中的所有 public 构造器。
 
An array of length 0 is returned if the
     * class has no public constructors, or if the class is an array class, or
     * if the class reflects a primitive type or void.
 
如果Class对象 代表的是 数组、基本类型、void、没有public构造器,将返回空数组。
 
 
@CallerSensitive
    public Constructor<?>[] getConstructors() throws SecurityException {
        checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
        return copyConstructors(privateGetDeclaredConstructors(true));
    }

  

    3.2、getDeclaredConstructors()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Returns an array of {@code Constructor} objects reflecting all the
     * constructors declared by the class represented by this
     * {@code Class} object.
 
These are public, protected, default
     * (package) access, and private constructors. 
 
返回 在类中声明的所有的构造器。
 
包括 publicprotecteddefaultprivate 构造器。
 
The elements in the array
     * returned are not sorted and are not in any particular order.
 
返回的构造器 没有排序。
 
If the
     * class has a default constructor, it is included in the returned array.
 
如果 类有一个默认的构造器,将返回默认构造器。
 
This method returns an array of length 0 if this {@code Class}
     * object represents an interface, a primitive type, an array class, or
     * void.
 
对于 接口、基本类型、数组、void ,将返回空数组。
 
@CallerSensitive
    public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
        checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
        return copyConstructors(privateGetDeclaredConstructors(false));
    }

 

4、name   

1
2
3
4
5
6
7
8
9
10
Returns the  name of the entity (class, interface, array class,
     * primitive type, or void) represented by this {@code Class} object,
     * as a {@code String}.
 
public String getName() {
        String name = this.name;
        if (name == null)
            this.name = name = getName0();
        return name;
    }

 

5、package

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Gets the package for this class.
 
The class loader of this class is used
     * to find the package.
 
该类的 类加载器 被用来 找到这个package
 
If the class was loaded by the bootstrap class
     * loader the set of packages loaded from CLASSPATH is searched to find the
     * package of the class.
 
如果 该类 被 根类加载器 加载,将会从Classpath 找到该类的package
 
Null is returned if no package object was created
     * by the class loader of this class.
 
如果 该类的类加载器 没有 package ,将返回null
 
public Package getPackage() {
        return Package.getPackage(this);
    }

  

6、getSimpleName

1
2
3
4
Returns the simple name of the underlying class as given in the source code.
Returns an empty string if the underlying class is anonymous.
 
返回 源码中给定的类的简单名称。

  

7、getModifiers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Returns the Java language modifiers for this class or interface, encoded
     * in an integer.
 
返回 类或接口 的修饰符,编码为int类型。
 
The modifiers consist of the Java Virtual Machine's
     * constants for {@code public}, {@code protected},
     * {@code private}, {@code final}, {@code static},
     * {@code abstract} and {@code interface}; they should be decoded
     * using the methods of class {@code Modifier}.
 
JVM的修饰符 包含 publicprotectedprivatefinalstaticabstractinterface
可以使用 Modifier进行处理 返回的int内容。
 
public native int getModifiers();

 

8、getSuperclass

1
2
3
4
5
6
7
Returns the {@code Class} representing the superclass of the entity
     * (class, interface, primitive type or void) represented by this
     * {@code Class}.
 
返回 代表 该类、接口、基本类型、void 的  直接父类。
 
public native Class<? super T> getSuperclass();

  

9、getInterfaces

1
2
3
4
Determines the interfaces implemented by the class or interface
     * represented by this object.
 
返回 该类或接口 实现的接口。

 

10、getGenericSuperclass

1
2
3
4
5
Returns the {@code Type} representing the direct superclass of
     * the entity (class, interface, primitive type or void) represented by
     * this {@code Class}.
 
返回 直接父类。

 

11、getGenericInterfaces

 

1
2
3
4
5
Returns the {@code Type}s representing the interfaces
     * directly implemented by the class or interface represented by
     * this object.
 
返回直接 实现的接口。

 

  

12、getEnumConstants

1
2
3
4
Returns the elements of this enum class or null if this
     * Class object does not represent an enum type.
 
返回 枚举类的元素 ,如果不是枚举类,返回null

  

13、getDeclaringClass

 

1
2
3
4
5
If the class or interface represented by this {@code Class} object
     * is a member of another class, returns the {@code Class} object
     * representing the class in which it was declared.
 
返回 成员内部类 所在的类。

  

14、getDeclaredClasses

1
2
3
4
5
6
7
8
9
Returns an array of {@code Class} objects reflecting all the
     * classes and interfaces declared as members of the class represented by
     * this {@code Class} object.
 
返回 该类 内部声明的所有成员class
 
This includes public, protected, default
     * (package) access, and private classes and interfaces declared by the
     * class, but excludes inherited classes and interfaces.

 

15、getDeclaredAnnotations

1
获取 所有声明的注解。

  

16、getClasses

1
2
3
4
5
Returns an array containing {@code Class} objects representing all
     * the public classes and interfaces that are members of the class
     * represented by this {@code Class} object. 
 
返回 该类 的所有public的成员class

  

17、method

    17.1、getDeclaredMethods

1
2
3
4
5
6
7
8
9
10
11
12
13
Returns an array containing {@code Method} objects reflecting all the
     * declared methods of the class or interface represented by this {@code
     * Class} object, including public, protected, default (package)
     * access, and private methods, but excluding inherited methods.
 
返回 该类声明的所有方法。
包括 publicprivate...
 
@CallerSensitive
    public Method[] getDeclaredMethods() throws SecurityException {
        checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
        return copyMethods(privateGetDeclaredMethods(false));
    }

  

    17.2、getMethods

1
2
3
4
5
6
7
8
9
10
11
12
13
Returns an array containing {@code Method} objects reflecting all the
     * public methods of the class or interface represented by this {@code
     * Class} object, including those declared by the class or interface and
     * those inherited from superclasses and superinterfaces.
 
返回 该类 声明的所有public方法。
包括父类。
 
@CallerSensitive
    public Method[] getMethods() throws SecurityException {
        checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
        return copyMethods(privateGetPublicMethods());
    }

  

18、getCanonicalName

1
返回 该类的 全限定名。

  

 

 

  

 

  

  

  

 

  

 

posted on   anpeiyong  阅读(52)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示