New instance java reflection mechanism

From , 5 Years ago, written in Java, viewed 79 times.
URL https://pastebin.vip/view/11b921ef
  1.         /**
  2.          * 新建实例 java反射机制
  3.          *
  4.          * @param className
  5.          * @param args
  6.          * @return
  7.          * @throws Exception
  8.          */
  9.         public Object newInstance(String className, Object[] args) throws Exception {
  10.  
  11.                 Class newoneClass = Class.forName(className);
  12.                 Class[] argsClass = new Class[args.length];
  13.  
  14.                 for (int i = 0, j = args.length; i < j; i++) {
  15.                         argsClass[i] = args[i].getClass();
  16.                 }
  17.  
  18.                 Constructor cons = newoneClass.getConstructor(argsClass);
  19.                 return cons.newInstance(args);
  20.         }

Reply to "New instance java reflection mechanism"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website