I need to check for an condition and if it is satisfied i need to return a class if it is not satisfied i need to return another class
private <T> d(String example) {
if(example.startsWith("example1"))
return new example1();
else if((example.startsWith("example2"))
return new example2();
}
I am not sure how to return it can u please explain.
You should return a super class or interface for both objects you could return. If you haven´t defined a super class for them, you can still return
Objectand do the not so goodinstanceofvalidation to know which class has been returned.Code Example: