85 java反射_1 _类对象

85 java反射_1 _类对象什么是类对象类的对象:基于某个类new出来的对象,也称为实例对象。类对象:类加载的产物,封装了一一个类的所有信息(类名、父类、接口、属性、方法、构造方法)-verbose:calss 显示类的加载过程 (在运行配置中)

获取类对象通过类的对象,获取类对象= new Student() ; Class c = s. getClass();通过类名获取类对象Class c =类名. class;通过静态方法获取类对象(推荐使用)Class c=Class. forName(“包名.类名”);package com.wlw.chapter12_reflex;public class TestPerson { public static void main(String[] args) throws Exception { /*Person zhangsan = new Person(); zhangsan.name = “张三”; zhangsan.eat();*/ getClazz(); } public static void getClazz() throws Exception{ //1.通过类的对象,获取类对象 Person zhangsan = new Person(); Class<?> class1 = zhangsan.getClass(); System.out.println(class1.hashCode()); //2.类名.class Class<?> class2 = Person.class; System.out.println(class2.hashCode()); //3.通过静态方法获取类对象(推荐使用) Class<?> class3 = Class.forName(“com.wlw.chapter12_reflex.Person”); System.out.println(class3.hashCode()); }}/*执行结果:116315788411631578841163157884*/

山不厌高,水不厌深。

85 java反射_1 _类对象

相关文章:

你感兴趣的文章:

标签云: