2
我有一個方法簽名,用於使用基於給定類型爲Method的getter方法的反射獲取setter方法。 簽名的方法是如下:lambda裏面collectors-map-java8中的類類型
Method getSetter(final Method getterMethod, final Class classType)
現在從一個類的方法我要地圖getter方法對相關setter方法一。我的代碼如下:
final Method[] methods = classType.getMethods();
Stream.of(methods)
.filter(ReflectionUtils::isGetter)
.collect(Collectors.toMap(Function.identity(), (method) -> getSetter(method, classType)));
我在getSetter(方法,classType所) 獲得編譯錯誤報告說,錯了第一種類型的參數實測值:<lambda parameter>
,需要:java.lang.reflect.Method
我也試過指定的類型lambda參數。看下面
Stream.of(methods)
.filter(ReflectionUtils::isGetter)
.collect(Collectors.toMap(Function.identity(), (Method method) -> getSetter(method, classType)));
現在它說不能推斷功能接口類型。
我無法重現此操作。 https://ideone.com/xt5Fb6請檢查您的導入,指定Java的確切版本以及您正在使用的編譯器。 –
嘿謝謝!其實對於getSetter方法,我拋出NoSuchMethodException我應該做一個try catch塊。我變了。有效。 – Sampath