当前位置:网站首页>Three ways of reflection

Three ways of reflection

2022-06-11 02:57:00 ambition_ forever

public class ReflectionDemo {
    public static void main(String[] args) {
       Class <?> cls = String.class; // It is only suitable for those that have been specified to operate before compilation Class
       try{ // The full pathname of the class has been specified
             Class <?> c= Class.forName("java.lang.String"); 
          String s=(String)c.newInstance();
       }catch(Exception e){
             System.out.println(e.getMessage());
       }
       //3、 Suitable for cases with object examples
       String str = new String();
       System.out.println(str.getClass());
    }
}
 

原网站

版权声明
本文为[ambition_ forever]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110232212162.html