Closing over immutable variable and accumulate values across multiple iterations as a lambda expression - Java 8
WebTarget in Jersey client is implemented as a immutable object, and any operations to change the state returns a new WebTarget. To add query params to it, which is coming in as a Map<> the following code was written. public WebTarget webTarget(String path, Map<String, String> queryMap) { WebTarget webTarget = client.target(this.address.getUrl()).path(path); if (queryMap != null) queryMap.entrySet().forEach(e -> webTarget.queryParam(e.getKey(), e.getValue())); return webTarget; } The problems here is every call to .queryParam() returns a new WebTarget and I'm stuck at how to accumulate as the