【发布时间】:2017-08-08 21:50:24
【问题描述】:
为什么这段代码不能为我编译?
我尝试使用流和 toMap 选项将列表转换为地图
List<CountryToPaymentMethodsDisplayRules>
paymentMethodDisplayRulesByCountryList =
gatway.getCountryPaymentMethodsDisplayRulesByCountry();
Map<PaymentMethod, CountryToPaymentMethodsDisplayRules>
countryToPaymentMethodsDisplayRulesMap = paymentMethodDisplayRulesByCountryList
.stream()
.collect(Collectors.toMap(type -> type.getCountryToPaymentMethodsDisplayRules().getPaymentMethod(),
type -> type));
public interface PaymentMethod extends Serializable {
}
public enum PaymentMethodType implements PaymentMethod, Serializable {
}
public interface CountryToPaymentMethodsDisplayRules {
public PaymentMethod getPaymentMethod();
}
public class CountryToPaymentMethodsDisplayRulesEntity implements CountryToPaymentMethodsDisplayRules, PersistentEntity<Long>, Serializable {
@Type(type = "com.plimus.core.payment.PaymentMethodTypeUserType")
@Column(name = "PAYMENT_TYPE")
private PaymentMethod paymentMethod;
}
这里有什么问题?
【问题讨论】:
-
好吧,你已经提供了一些代码(我已经为你重新格式化了 - 请阅读格式化帮助并避免发布,直到预览显示合理的格式),但你还没有说它不以什么方式'不起作用...理想情况下,将其重写为minimal reproducible example。
-
我找不到方法 getCountryToPaymentMethodsDisplayRules。你能提供一些关于这个方法的信息吗?
-
确实,这里的有什么问题?它会产生异常吗?它会产生一张空地图吗?它会无限期地运行吗?我们可能永远不会知道!
标签: java java-8 java-stream collectors