Код: Выделить всё
public static T getCountrySpecificComponent(UK uk, US us) {
Country country = CountryContext.getCountry();
if (country == Country.US) {
return us;
} else if (country == Country.UK) {
return uk;
} else {
throw new IllegalStateException("Unhandled country returned: "+country);
}
}
Код: Выделить всё
public interface Repository{
List findAll();
}
public interface RepositoryUS extends Repository{}
public interface RepositoryUK extends Repository{}
Код: Выделить всё
RepositoryUK uk = ...
RepositoryUS us = ...
Код: Выделить всё
List users = getCountrySpecificComponent(uk, us).findAll();
Код: Выделить всё
List users = ((Repository)getCountrySpecificComponent(uk, us)).findAll();
Подробнее здесь: https://stackoverflow.com/questions/107 ... -in-java-7