反射的调用接口的写法:
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public static <T> T callStaticObjectMethod(Class<?> clazz, Class<T> returnType, String method, Class<?>[] parameterTypes,
Object... values)
throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method declaredMethod = clazz.getDeclaredMethod(method, parameterTypes);
declaredMethod.setAccessible(true);
return (T) declaredMethod.invoke(null, values);
}
private static final String PHONE_ENCRYPT_UTIL_CLASS = "com.miui.enterprise.PhoneEncryptUtil";
private static boolean isEncryptedNumber(String number) {
try {
Class phoneEncryptUtil = Class.forName(PHONE_ENCRYPT_UTIL_CLASS);
return callStaticObjectMethod(phoneEncryptUtil, boolean.class, "isEncryptedNumber",
new Class[]{String.class}, number);
} catch (Exception e) {
return false;
}
}
posted on 2019-03-25 16:29 zhang11111wei 阅读(1021) 评论(0) 编辑 收藏 举报