下面是其中lambda表達式是本方法和我希望它在其它方法中使用,以及不重複。Java的8如何重用蘭巴表達
public FeatureView getFeature(String featurekey) {
Feature feature = featureRepository.findByPrimaryKey(featurekey)
.orElseThrow(() -> new WebApplicationException(new ResponseEntity<>(
ServiceError.of(404, String.format(FEATURE_NOT_FOUND, featurekey)), HttpStatus.NOT_FOUND)));
return Feature.getFeatureView(feature, extractFeatureStatus(feature));
}
蘭巴表達
() -> new WebApplicationException(new ResponseEntity<>(
ServiceError.of(404, String.format(FEATURE_NOT_FOUND, featurekey)), HttpStatus.NOT_FOUND))
謝謝。我如何將featurekey(變量)傳遞給此供應商? – Shoaib627
@ Shoaib627你不通過它。您需要將代碼放在與'featureKey'相同的作用域中。 – Sweeper
@ Shoaib627增加了一個變體,你可以在這裏傳遞featureKey ... – Roland