//1. For Object.getClass()
使用apache中API替代.
/**
* replace Object.getClass().
* @param obj
* @return
* @throws ClassNotFoundException
*/
public static Class<?> getClassForObject(Object obj){
Class<?> clazz = null;
if (obj == null) {
throw new NullPointerException();
}
try {
clazz = ClassUtils.getClass(ClassUtils.getName(obj));//org.apachemons.lang3.ClassUtils;
} catch (ClassNotFoundException e) {
ValidationUtils.myLoggerError(LOGGER, e.getMessage(),e);
}
return clazz;
}
//2. For System.currentTimeMillis()
public static long getCurrentTimeMillis() {
return Instant.now().toEpochMilli();
}
// 3. For public native boolean isAssignableFrom(Class<?> cls);
/**
* Checks if one {@code Class} can be assigned to a variable of
* another {@code Class}.</p>
* @param cls: the Class to check, may be null
* @param tocls: the Class to try to assign into, returns false if null
* @return
*/
public static boolean isAssignableFromForCC( Class<?> cls, Class<?> tocls) {
return ClassUtils.isAssignable(cls, tocls);// use org.apachemons.lang3.ClassUtils;
}
//4. For obj.hashCode()
public static int hashCodeForCC(Object obj) {
return ObjectUtils.hashCode(obj);//org.apachemons.lang3.ObjectUtils;
}
//5. For getModifiers()
public static int getModifiersForCC(Class clazz) {
return ReflectUtils.getClassInfo(clazz).getModifiers();//org.springframework.cglib.core.ReflectUtils;
}
//6. For public native boolean isInstance(Object obj);we can use keyword instanceof replace it.
//7. For Thread.sleep(5000L);
TimeUnit.SECONDS.sleep(5);
//8.Thread.currentThread().getContextClassLoader()
Class.getClassLoader();
更多推荐
HP fortify Unsafe JNI.
发布评论