Thursday, 8 August 2013

Generics, Interface puzzle, what is the advantage of declaring interface like this?

Generics, Interface puzzle, what is the advantage of declaring interface
like this?

In my project I see the interface like this. All the model extend the
interface. I am wondering what is the use ?
public interface IModel {
<T> T modelTo(Class<T> clazz);
}
public interface IPerson extends IModel {
public String getFirstName();
public void setFirstName(String firstName);
public String getMiddleName();
public void setMiddleName(String middleName);
}
Then in some places in the code I see like
@Override
public void modelJoin(IModel parent, IModel sample) {
//Some code
IPerson sample= sample.modelTo(IPerson.class);
IPerson person = parent.modelTo(IPerson.class);
//Some code
}
Can you explain me the insight of it ?

No comments:

Post a Comment