java.lang.Class这个类有什么用?

kinglds 2004-10-11 02:32:20
java.lang.Class这个类有什么用?
...全文
313 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
夜魔009 2004-12-01
  • 打赏
  • 举报
回复
还有问题吗?
debug148 2004-11-14
  • 打赏
  • 举报
回复
ding
夜魔009 2004-11-14
  • 打赏
  • 举报
回复
java.lang是基础类包!!!会被自动强制包含在所有的JAVA中,不过是隐含的!!!其中有很多类,比如:Boolean、Long、Math......等
所以它是最重要的类!!!
网络咖啡 2004-11-14
  • 打赏
  • 举报
回复
楼上的楼上说得不错
Drate 2004-10-11
  • 打赏
  • 举报
回复
java.lang
Class Class
java.lang.Object
|
+-java.lang.Class

All Implemented Interfaces:
Serializable

--------------------------------------------------------------------------------

public final class Class
extends Object
implements Serializable
Instances of the class Class represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.

Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.

The following example uses a Class object to print the class name of an object:


void printClassName(Object obj) {
System.out.println("The class of " obj
" is " obj.getClass().getName());
}



Since:
JDK1.0
晨星 2004-10-11
  • 打赏
  • 举报
回复 1
Class对象能够代表被JVM加载进来的所有的类,注意是这些类本身,而不是这些类的实例,通常,对程序员来说,类是产生实例的模板,但对JVM来说,每一个这种模板当然也是一个对象,Class的实例就能代表这种类对象,该类的一些方法就能获得许多关于类的信息,比如某个类的名字,这个类所拥有的方法等等。我觉得能够在运行时获取许多类本身的信息,这是许多编程框架(如struts)实现的基础,。

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧