JDK8 + IntelliJ IDEA 2018.3
package com.ChenJiangT.reflect; import com.ChenJiangT.pojo.Student; public class Zy1 { public static void main(String[] args) { Student student=new Student(); Class clz= student.getClass(); Class clz3= Student.class; Class clz2=null; try { clz2=Class.forName("com.kangcong.zy2.pojo.Student"); } catch (ClassNotFoundException e) { e.printStackTrace(); } System.out.println(clz==clz3); System.out.println(clz2==clz); System.out.println(clz2==clz3); } }
package com.ChenJiangT.util; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; public class DButil { static Properties pro = new Properties(); private static String DRIVER; private static String URL; private static String USER; private static String PASSWORD; static { InputStream is = DButil.class.getClassLoader().getResourceAsStream("jdbc.properties"); try { pro.load(is); DRIVER= pro.getProperty("driver"); URL=pro.getProperty("url"); USER=pro.getProperty("user"); PASSWORD=pro.getProperty("password"); Class.forName(DRIVER); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } public static Connection getcon(String url, String user, String pwd) { try { Connection con = DriverManager.getConnection(url, user, pwd); return con; } catch (SQLException e) { e.printStackTrace(); } return null; } public static void main(String[] args) { Connection getcon = DButil.getcon(URL, USER, PASSWORD); System.out.println(getcon); } }
1).演示用eclipse如何加入jar包,先只是引入beanutils包,等程序运行出错后再引入logging包。
2).在前面内省例子的基础上,用BeanUtils类先get原来设置好的属性,再将其set为一个新值。
3).get属性时返回的结果为字符串, set属性时可以接受任意类型的对象,通常使用字符串。
原文:https://www.cnblogs.com/CjtBlog/p/13550201.html