java反射

java反射调用一个类带参数的方法,调用Father类doSomething方法:

try {
			Class clazz = Class.forName("com.test.design.Father");
			Object action = clazz.newInstance();
			Method method = clazz.getMethod("doSomething", Map.class);
			HashMap map = new HashMap();
			method.invoke(action, map);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		}




你可能感兴趣的:(java反射)