小编Yar*_*zur的帖子

Java 8 Collection stream Collectors.toMap

为什么这段代码不能为我编译?

我尝试使用stream和toMap选项将List转换为Map

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;
}
Run Code Online (Sandbox Code Playgroud)

这有什么不对?

java java-8 java-stream collectors

-1
推荐指数
1
解决办法
1万
查看次数

标签 统计

collectors ×1

java ×1

java-8 ×1

java-stream ×1