Webrev for JAX-WS/JAXB/SAAJ services
Paul Sandoz
paul.sandoz at oracle.com
Tue May 22 03:32:18 PDT 2012
On May 17, 2012, at 7:07 PM, Jesse Glick wrote:
> On 05/17/2012 12:12 PM, Paul Sandoz wrote:
>> e.g. a default provider always occurs after any non-default.
>
> Would seem simpler to not register this provider in module-info.java at all, and just use the simple idiom:
>
> for (Service s : ServiceLoader.load(Service.class)) {
> if (s.handles(arg)) {
> return s.dealWith(arg);
> }
> }
> // could of course also inline this code:
> Service s = new DefaultService();
> return s.dealWith(arg);
Good point. I was thinking it would be useful to capture simple idioms like this in ServiceLoader.
With lambda one could potentially do:
ServiceLoader.load(Service.class).
filter(s -> s.handles(arg)).
getFirstOrElse(() -> new DefaultService()). // this method does not currently exist in lambda
dealWith(arg);
And with ServiceLoader:
// Dunno if there is a short hand for referencing a constructor, DefaultService::?
ServiceLoader.firstOrDefault(() -> new DefaultService())
ServiceLoader.findOrDefault(s -> s.handles(arg), () -> new DefaultService())
Paul.
More information about the jigsaw-dev
mailing list