
com.github.df.restypass.util.ClassTools Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resty-pass Show documentation
Show all versions of resty-pass Show documentation
High-Performance Restful Client Library
package com.github.df.restypass.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class工具类
* Created by darrenfu on 17-7-23.
*/
@SuppressWarnings("unused")
public class ClassTools {
private static final Logger log = LoggerFactory.getLogger(ClassTools.class);
/**
* Cast to t.
*
* @param the type parameter
* @param obj the obj
* @param clz the clz
* @return the t
*/
public static T castTo(Object obj, Class clz) {
return clz.cast(obj);
}
/**
* Instance t.
*
* @param the type parameter
* @param targetClz the target clz
* @return the t
*/
public static T instance(Class targetClz) {
try {
return targetClz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
log.warn("Instantiation failed:{}", e.getMessage(), e);
}
return null;
}
/**
* Has class boolean.
*
* @param clz the clz
* @return the boolean
*/
public static boolean hasClass(String clz) {
try {
Class.forName(clz);
} catch (ClassNotFoundException e) {
return false;
}
return true;
}
/**
* Gets class.
*
* @param clz the clz
* @return the class
*/
public static Class> getClass(String clz) {
try {
return Class.forName(clz);
} catch (ClassNotFoundException e) {
log.error("no class found:{}", clz, e);
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy