类的初始化
package 反射;
public class Test02 {
static {
System.out.println("MAin类被加载");
}
public static void main(String[] args) throws ClassNotFoundException {
//1 主动引用
// Son son = new Son();
/*
MAin类被加载
父类被加载
子类被加载
*/
//2.反射也会产生主动引用
// Class.forName("反射.Son");
/*
MAin类被加载
父类被加载
子类被加载
*/
//3.不会产生类的引用的方法
// System.out.println(Son.b);
// 当通过子类引用父类的静态变量。不会导致子类初始化
/*
MAin类被加载
父类被加载
2
*/
// Son[] a=new Son[5] ;//只有main类被加载 通过数组定义类引用,不会触发此类的初始化
// 引用常量不会触发此类的初始化(常量在链接阶段就存入调用类的常量池中了)
System.out.println(Son.M);
/*
* MAin类被加载
* 1
*/
}
}
class Father{
static int b=2;
static {
System.out.println("父类被加载");
}
}
class Son extends Father{
static {
System.out.println("子类被加载");
m=300;
}
static int m =100;
static final int M=1;
}
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JjmwGekx-1597380825297)(C:\Users\13452\AppData\Roaming\Typora\typora-user-images\image-20200812142043606.png)]
反射
user
package 反射;
public class User {
private String name;
private int id;
private int age;
private void test(){
}
public User() {
super();
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", id=" + id +
", age=" + age +
'}';
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public User(String name, int id, int age) {
this.name = name;
this.id = id;
this.age = age;
}
public User(String name) {
this.name = name;
}
}
Test03 反射获取类的属性方法 构造器
package 反射;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class Test03 {
public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
Class c1=Class.forName("反射.User");
//获得类的名字
System.out.println(c1.getName());//获得包名+类名
System.out.println(c1.getSimpleName());//获得类名
System.out.println("+++++++++++++++++++++++++++++++");
//获得类的属性
Field[] fields = c1.getFields();//getFields 只能找到public 的属性
fields = c1.getDeclaredFields();//getDeclaredFields 能找到所有的属性
for (Field field : fields) {
System.out.println(field);
}
System.out.println("+++++++++++++++++++++++++++++++");
//获得指定属性的值
Field name = c1.getDeclaredField("name");
System.out.println(name);
System.out.println("+++++++++++++++++++++++++++++++");
//获得类的方法
Method[] methods = c1.getMethods();//获得本类及其父类的所有方法
for (Method method : methods) {
System.out.println("正常的"+method);
}
//获得本类的所有方法
System.out.println("+++++++++++++++++++++++++++++++");
methods =c1.getDeclaredMethods();
for (Method method : methods) {
System.out.println("getDeclaredMethods"+method);
}
System.out.println("+++++++++++++++++++++++++++++++");
//获得指定的方法
Method getName = c1.getMethod("getName", null);
Method setName = c1.getMethod("setName", String.class);
System.out.println(getName);
System.out.println(setName);
//获得类的构造器
System.out.println("+++++++++++++++++++++++++++++++");
Constructor[] constructors = c1.getConstructors();//getConstructors 获得public 方法
for (Constructor constructor : constructors) {
System.out.println(constructor);
}
for (Constructor constructor : constructors = c1.getDeclaredConstructors()) {
//getDeclaredConstructors 获得所有方法
System.out.println("***"+constructor);
}
//获得指定的构造器
Constructor declaredConstructor = c1.getDeclaredConstructor(String.class);
System.out.println("指定:"+declaredConstructor);
}
}
运行结果
"C:\Program Files\Java\jdk1.8.0_231\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar=57082:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_231\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\rt.jar;D:\Ideaa_item\daima\javaStudy\out\production\javaStudy;D:\Ideaa_item\daima\javaStudy\src\lib\commons-io-1.3.2.jar" 反射.Test03
反射.User
User
+++++++++++++++++++++++++++++++
private java.lang.String 反射.User.name
private int 反射.User.id
private int 反射.User.age
+++++++++++++++++++++++++++++++
private java.lang.String 反射.User.name
+++++++++++++++++++++++++++++++
正常的public java.lang.String 反射.User.toString()
正常的public java.lang.String 反射.User.getName()
正常的public int 反射.User.getId()
正常的public void 反射.User.setName(java.lang.String)
正常的public void 反射.User.setAge(int)
正常的public void 反射.User.setId(int)
正常的public int 反射.User.getAge()
正常的public final void java.lang.Object.wait() throws java.lang.InterruptedException
正常的public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
正常的public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
正常的public boolean java.lang.Object.equals(java.lang.Object)
正常的public native int java.lang.Object.hashCode()
正常的public final native java.lang.Class java.lang.Object.getClass()
正常的public final native void java.lang.Object.notify()
正常的public final native void java.lang.Object.notifyAll()
+++++++++++++++++++++++++++++++
getDeclaredMethodspublic java.lang.String 反射.User.toString()
getDeclaredMethodspublic java.lang.String 反射.User.getName()
getDeclaredMethodspublic int 反射.User.getId()
getDeclaredMethodspublic void 反射.User.setName(java.lang.String)
getDeclaredMethodsprivate void 反射.User.test()
getDeclaredMethodspublic void 反射.User.setAge(int)
getDeclaredMethodspublic void 反射.User.setId(int)
getDeclaredMethodspublic int 反射.User.getAge()
+++++++++++++++++++++++++++++++
public java.lang.String 反射.User.getName()
public void 反射.User.setName(java.lang.String)
+++++++++++++++++++++++++++++++
public 反射.User(java.lang.String,int,int)
public 反射.User()
public 反射.User(java.lang.String)
***public 反射.User(java.lang.String,int,int)
***public 反射.User()
***public 反射.User(java.lang.String)
指定:public 反射.User(java.lang.String)
Process finished with exit code 0
Test 04 通过反射 构造对象 调用方法 操作属性
package 反射;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Test04 {
public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
//获得class对象
Class c1 = Class.forName("反射.User");
System.out.println(c1);
//构造一个对象
User user = (User)c1.newInstance();//本质是调用了类的无参构造器
System.out.println(user);
//通过构造器创建对象 调用的是有参构造器
Constructor Constructor = c1.getDeclaredConstructor(String.class, int.class, int.class);
User user1 = (User) Constructor.newInstance("曾某", 13, 13);
System.out.println(user1);
//通过反射调用普通方法
User user3 = (User)c1.newInstance();
//通过反射获得一个方法
Method setName = c1.getDeclaredMethod("setName", String.class);
//invoke :激活的意思
//(对象,"方法的值")
setName.invoke(user3,"张三");
System.out.println(user3.getName());
//通过反射操作属性
User user4 = (User) c1.newInstance();
Field name = c1.getDeclaredField("name");
//不能直接操作私有属性,需要关闭程序的安全检测,属性或方法的setSAccessible(true)
//true 是关闭
name.setAccessible(true);
name.set(user4,"李四");
System.out.println(user4.getName());
}
}
运行结果
"C:\Program Files\Java\jdk1.8.0_231\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar=57121:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_231\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\rt.jar;D:\Ideaa_item\daima\javaStudy\out\production\javaStudy;D:\Ideaa_item\daima\javaStudy\src\lib\commons-io-1.3.2.jar" 反射.Test04
class 反射.User
User{name='null', id=0, age=0}
User{name='曾某', id=13, age=13}
张三
李四
Process finished with exit code 0
Test05 检测性能
package 反射;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Test05 {
//普通方式调用
public static void test01(){
User user=new User();
Long startTime =System.currentTimeMillis();
for (int i = 0; i < 1000000000; i++) {
user.getName();
}
Long endTime =System.currentTimeMillis();
System.out.println("普通方式执行十亿次:"+(endTime-startTime)+"ms");
}
//反射方式调用
public static void test02() throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
User user=new User();
Class c1 = user.getClass();
Method getName = c1.getDeclaredMethod("getName", null);
Long startTime =System.currentTimeMillis();
for (int i = 0; i < 1000000000; i++) {
getName.invoke(user,null);
}
Long endTime =System.currentTimeMillis();
System.out.println("反射方式执行十亿次:"+(endTime-startTime)+"ms");
}
//关闭检测方式调用
public static void test03() throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
User user=new User();
Class c1 = user.getClass();
Method getName = c1.getDeclaredMethod("getName", null);
getName.setAccessible(true);
Long startTime =System.currentTimeMillis();
for (int i = 0; i < 1000000000; i++) {
getName.invoke(user,null);
}
Long endTime =System.currentTimeMillis();
System.out.println("关闭检测方式执行十亿次:"+(endTime-startTime)+"ms");
}
public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
test01();
test02();
test03();
}
}
运行结果
"C:\Program Files\Java\jdk1.8.0_231\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar=57130:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_231\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\rt.jar;D:\Ideaa_item\daima\javaStudy\out\production\javaStudy;D:\Ideaa_item\daima\javaStudy\src\lib\commons-io-1.3.2.jar" 反射.Test05
普通方式执行十亿次:5ms
反射方式执行十亿次:2153ms
关闭检测方式执行十亿次:1510ms
Process finished with exit code 0
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7BxyyNvc-1597380825299)(C:\Users\13452\AppData\Roaming\Typora\typora-user-images\image-20200812161347307.png)]
Test06 通过反射获取泛型
package 反射;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
//通过反射获取泛型
public class Test06 {
public void test01(Map<String,User> map, List<User> list){
System.out.println("test01");
}
public Map<String,User> test02(){
System.out.println("test02");
return null;
}
public static void main(String[] args) throws NoSuchMethodException {
//通过类名获取方法
Method method = Test06.class.getMethod("test01", Map.class, List.class);
//通过方法获取参数类型
Type[] genericParameterTypes = method.getGenericParameterTypes();
for (Type genericParameterType : genericParameterTypes) {
System.out.println("*"+genericParameterType);
//如果genericParameterType 属于 ParameterizedType(结构化参数化类型)->Coll ection<String>
if(genericParameterType instanceof ParameterizedType ){
//强转类型 getActualTypeArguments()获得它的一个真实参数信息
Type[] actualTypeArguments = ((ParameterizedType) genericParameterType).getActualTypeArguments();
for (Type actualTypeArgument : actualTypeArguments) {
System.out.println("888"+actualTypeArgument);
}
}
}
System.out.println("-----------------------------------------------");
method= Test06.class.getMethod("test02", null);
//获取返回值类型 getGenericReturnType
Type genericReturnType = method.getGenericReturnType();
if(genericReturnType instanceof ParameterizedType){
Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
for (Type actualTypeArgument : actualTypeArguments) {
System.out.println("--"+actualTypeArgument);
}
}
}
}
运行结果
*java.util.Map<java.lang.String, 反射.User>
888class java.lang.String
888class 反射.User
*java.util.List<反射.User>
888class 反射.User
-----------------------------------------------
--class java.lang.String
--class 反射.User
运行结果
@反射.TableZeng(value=db_student)
db_student
db_name
varchar
3
Test07 通过反射获得注解
package 反射;
import java.lang.annotation.*;
import java.lang.reflect.Field;
//练习反射操作注解
public class test07 {
public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
Class c1 = Class.forName("反射.Student2");
//通过反射获得注解
Annotation[] annotations = c1.getAnnotations();
for (Annotation annotation : annotations) {
System.out.println(annotation);
}
//获得注解Value的值。
TableZeng tableZeng = (TableZeng)c1.getAnnotation(TableZeng.class);
String value = tableZeng.value();
System.out.println(value);
//获得类指定的注解
Field f = c1.getDeclaredField("name");
FieldZeng annotation = f.getAnnotation(FieldZeng.class);
System.out.println(annotation.columnName());
System.out.println(annotation.type());
System.out.println(annotation.length());
}
}
@TableZeng("db_student")
class Student2{
@FieldZeng(columnName = "db_id",type = "int",length = 10)
private int id;
@FieldZeng(columnName = "db_age",type = "int",length = 10)
private int age;
@FieldZeng(columnName = "db_name",type = "varchar",length = 3)
private String name;
@Override
public String toString() {
return "Student2{" +
"id=" + id +
", age=" + age +
", name='" + name + '\'' +
'}';
}
public Student2() {
super();
}
public Student2(int id, int age, String name) {
this.id = id;
this.age = age;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//类名的注解
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface TableZeng{
String value();
}
//属性的注解
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface FieldZeng{
String columnName();
String type();
int length();
}
运行结果
@反射.TableZeng(value=db_student)
db_student
db_name
varchar
3
Test08 类加载器 双亲委派机制
package 反射;
//类加载器
public class Test08 {
public static void main(String[] args) throws ClassNotFoundException {
//获取系统类的加载器
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
System.out.println(systemClassLoader);
//获取系统类的加载器的父类加载器-->扩展加载器
ClassLoader parent = systemClassLoader.getParent();
System.out.println(parent);
//获取扩展类加载器的父类加载器-->根加载器(c/c++写的) 无法获取打印 null
ClassLoader parent1 = parent.getParent();
System.out.println(parent1);
//测试当前类是哪个加载器加载的
ClassLoader classLoader = Class.forName("反射.Test08").getClassLoader();
System.out.println(classLoader);
//测试Jdk内置类是谁加载的
ClassLoader classLoader1 = Class.forName("java.lang.String").getClassLoader();
System.out.println(classLoader1);
//如何获得系统类加载器可以加载的路径
System.out.println(System.getProperty("java.class.path"));
//双亲委派机制
/*
假如自定义 了 一个 java.lang.String 类
JDK里已经定义了一个 java.lang.String ,因为双亲委派机制,自己定义的这个类根本跑不起来
会多重检测安全性 从类加载器往上找 根加载器存在了,就不会用自定义的java.lang.String ,
用的是根加载器里的 java.lang.String,
*/
}
}
运行结果
sun.misc.Launcher$AppClassLoader@18b4aac2
sun.misc.Launcher$ExtClassLoader@74a14482
null
sun.misc.Launcher$AppClassLoader@18b4aac2
null
C:\Program Files\Java\jdk1.8.0_231\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\rt.jar;D:\Ideaa_item\daima\javaStudy\out\production\javaStudy;D:\Ideaa_item\daima\javaStudy\src\lib\commons-io-1.3.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar
双亲委派机制
假如自定义 了 一个 java.lang.String 类 JDK里已经定义了一个 java.lang.String ,因为双亲委派机制,自己定义的这个类根本跑不起来 会多重检测安全性 从类加载器往上找 根加载器存在了,就不会用自定义的java.lang.String , 用的是根加载器里的 java.lang.String,