我正在使用一个接口方法,它返回带有这些键值的地图。
public interface IParse<T> {
Map<String, T> parse(); //T is an enum type
}
现在在实现类中,我使用函数解析
public class TestClass1 implements IParse
{
public Map<String, EnumType1> parse()
{
Map<String, EnumType1> map1 = new HashMap<>();
// Logic to fill the map
return map1;
}
}
public class TestClass2 implements IParse
{
public Map<String, EnumType2> parse()
{
Map<String, EnumType2> map2 = new HashMap<>();
// Logic to fill the map
return map2;
}
}
并返回包含适当枚举类型的地图。但是eclipse似乎并不喜欢它。其中一个帮助选项显示“推断通用类型参数”。
现在在上面的例子中,我如何使用正确返回地图而不进行任何类型转换。有没有其他方法我可以使用接口方法返回值包含值作为枚举类类型的映射。请举例说明如何做到这一点。
如果需要进一步的详细信息,请与我们联系。