Java examples for Reflection:Method
get Class Mutator Method
import java.lang.reflect.Method; public class Main{ public static void main(String[] argv) throws Exception{ Class clazz = String.class; String propertyName = "java2s.com"; Class params = String.class; System.out.println(getMutator(clazz,propertyName,params)); }// w ww . j ava2 s . c o m public static final String[] MUTATOR_PREFIXES = new String[] { "set" }; public static Method getMutator(Class clazz, String propertyName, Class... params) { propertyName = StringHelper.capitalize(propertyName); for (String prefix : MUTATOR_PREFIXES) { try { return clazz.getDeclaredMethod(prefix + propertyName, params); } catch (NoSuchMethodException ignored) { // ignore } } return null; } }