public static string GetObjectPropertyValue<T>(T t, string propertyname){ Type type = typeof(T); PropertyInfo property = type.GetProperty(propertyname); if (property == null) return string.Empty; object o = property.GetValue(t, null); if (o == n…
import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class BeanChangeUtil<T> { public static <T> void main(String[] args) { User u1 = new User("1", true, "a"); User u…
Field[] field = behavior.getClass().getDeclaredFields(); for (int i = 0; i < field.length; i++) { String name = field[i].getName(); name = name.substring(0, 1).toUpperCase() + name.substring(1);//找到首位改成大写形式 String type = field[i].getGenericType().toS…
获取所有字段的值: public void PrintProperties(Object obj) { Type type = obj.GetType(); foreach( PropertyInfo p in type.GetProperties()) { Console.Write(p.GetValue()); } }…
Service1.java package reflection; public class Service1 { public void doService1(){ System.out.println("业务方法1"); } } Service2.java package reflection; public class Service2 { public void doService2(){ System.out.println("业务方法1"); } } s…