java需要class 您所在的位置:网站首页 需要class是什么错误 java需要class

java需要class

2024-07-10 23:04| 来源: 网络整理| 查看: 265

84c7ad76e865a1074c34ce99d6078387.png

本教程操作环境:windows7系统、java10版,DELL G3电脑。

1.概念

Class 类是在Java语言中定义一个特定类的实现,在java.lang 包中。一个类的定义包含成员变量,成员方法,还有这个类实现的接口,以及这个类的父类。Class类的对象用于表示当前运行的 Java 应用程序中的类和接口。

比如:每个数组均属于一个 Class 类对象,所有具有相同元素类型和维数的数组共享一个Class 对象。基本的 Java 类型(boolean, byte, char, short,int, long, float 和 double) 和 void 类型也可表示为 Class 对象。

2.特征

class类没有公有的构造方法,它由JVM自动调用(在new对象或者加载-classLoader时)。

下面的方法作用是打印出对象的class name:void printClassName(Object obj) {

System.out.println("The class of " + obj +

" is " + obj.getClass().getName());

}

同样可以根据class literal 获得class name:System.out.println("The name of class Foo is: "+Foo.class.getName());//你可以将Foo改为void尝试下。

3.使用实例public final class Class implements java.io.Serializable,GenericDeclaration,Type, AnnotatedElement {

private static final int ANNOTATION= 0x00002000;

private static final int ENUM      = 0x00004000;

private static final int SYNTHETIC = 0x00001000;

private static native void registerNatives();

static {

registerNatives();

}

/*

* Private constructor. Only the Java Virtual Machine creates Class objects.(私有构造,只能由JVM创建该类)

* This constructor is not used and prevents the default constructor being

* generated.

*/

private Class(ClassLoader loader) {

// Initialize final field for classLoader.  The initialization value of non-null

// prevents future JIT optimizations from assuming this final field is null.

classLoader = loader;

}

以上就是关于java中需要class的讲解,可以说作为最基础的类,是所有类的共同属性。在实例的使用时,同样是不可缺少的存在,相信经过本篇的学习,大家已经能够明白class的重要性。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有