1 package reflection;
 2 
 3 import bean.User;
 4 
 5 public class ReflectionDemo {
 6     public static void main(String[] args) throws Exception {
 7         //获取类名,含包名
 8         System.out.println(User.class.getName());
 9 
10         //通过类名反射实例化对象
11         User user = (User) Class.forName(User.class.getName()).newInstance();
12         System.out.println(user);
13 
14 
15     }

运行结果:

bean.User
User[name='null', age=null, address='null']

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2021-12-10
  • 2022-03-02
  • 2021-12-27
  • 2021-06-15
猜你喜欢
  • 2022-12-23
  • 2021-11-27
  • 2021-08-08
  • 2021-10-09
  • 2022-12-23
  • 2022-01-22
  • 2022-02-06
相关资源
相似解决方案