Skip to content

Generic method return – JAVA

October 24, 2013

public <T> T getValue (Class<T> resultClass, String idJurisd, String nmView, String nmKey){
T result = null;
ReportabilityOutput record = this.get(generateKey(idJurisd, nmView, nmKey));
if(record != null){
result = resultClass.cast(record.getIntValue());
}else if(resultClass.equals(String.class)){
result = resultClass.cast(record.getStrValue());
}else if(resultClass.equals(Date.class)){
result = resultClass.cast(record.getDateValue());
}else if(resultClass.equals(Float.class)){
result = resultClass.cast(record.getFloatValue());
return result;

Sample call:

Integer buffer = this.getValue(Integer.class, "A", "B", "C");

From → Interests

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: