爲什麼這段代碼不適合我?Java 8 Collection流Collectors.toMap
我嘗試轉換列表使用流和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;
}
這裏有什麼問題到地圖?
,那麼您已經提供了一些代碼(我已經重新格式化你 - 請閱讀的格式幫助,避免發佈,直到預覽顯示合理的格式),但你有沒有用什麼方式說,不起作用...理想情況下,將其重寫爲[mcve]。 –
我找不到方法getCountryToPaymentMethodsDisplayRules。你能提供一些有關這種方法的信息嗎? –
確實,這裏*錯在哪裏?它是否會產生異常?它是否會生成空白的地圖?它會無限期地運行嗎?我們可能永遠不知道! –