I am developing a generic utility which should have minimum size and code duplication. Is this code good or bad java practise?
public static <T> T getProperty(String fileName,String propertyName, Class<T> type ){
T result=null;
try{
Properties properties=propertyMap.get(fileName);
if(type.getName().equals("java.lang.Float")){
result=type.cast(java.lang.Float.valueOf(properties.getProperty(propertyName)));
}else if(type.getName().equals("java.lang.Long")){
result=type.cast(java.lang.Long.valueOf(properties.getProperty(propertyName)));
}else if(type.getName().equals("java.lang.String")){
result=type.cast(java.lang.String.valueOf(properties.getProperty(propertyName)));
}else if(type.getName().equals("java.lang.Double")){
result=type.cast(java.lang.Double.valueOf(properties.getProperty(propertyName)));
}else if(type.getName().equals("java.lang.Integer")){
result=type.cast(java.lang.Integer.valueOf(properties.getProperty(propertyName)));
}
}catch(ClassCastException e){
logger.error(CommonUtils.getExceptionTrace(e));
}catch(NullPointerException e){
logger.error(CommonUtils.getExceptionTrace(e));
}catch(Exception e){
logger.error(CommonUtils.getExceptionTrace(e));
}
return result;
}
RuntimeExceptions