我正在了解FunctionalInterface
Java 8 中存在哪些。在做了一些基本的功能示例之后,我尝试对 GenericType 参数做同样的事情。
public class Main {
public enum LocType {
Area, Country
}
public <T> Function<T, T> getCreateFunction(LocType type) {
AreaService areaService = new AreaService();
CountryService countryService = new CountryService();
switch(type) {
case Area : return areaService::createArea;
case Country : return countryService::createCountry;
default : return null;
}
}
}
public class AreaService {
public Area createArea(Area area) {
// some logic
return area;
}
}
public class CountryService {
public Country createCountry(Country country) {
// some logic
return country;
}
}
// Area & Country are Model Classes
但是eclipse编译器会抛出错误
The type AreaService does not define createArea(T) that is applicable here
不能在 FunctionalInterface 中定义泛型类型参数吗?