package com.github.peterpaul.cli.instantiator;

import com.github.peterpaul.cli.fn.ExceptionCatchingSupplier;
import com.github.peterpaul.cli.fn.Supplier;

public class ByServiceLoaderOrNewClassInstanceInstantiator implements Instantiator {
    private final ClassInstantiator classInstantiator = new ClassInstantiator();
    private final ServiceLoaderInstantiator serviceLoaderInstantiator = new ServiceLoaderInstantiator();

    @Override
    public <T> T instantiate(Class<T> aClass) {
        return ExceptionCatchingSupplier.catchingFor(new Supplier<T>() {
            @Override
            public T supply() {
                return serviceLoaderInstantiator.instantiate(aClass);
            }
        }).supply().orElseGet(new java.util.function.Supplier<T>() {
            @Override
            public T get() {
                return classInstantiator.instantiate(aClass);
            }
        });
    }
}

@@ -40,32 +40,39 @@
 tiator;%0A%0Aimport 
+static 
 com.github.peter
@@ -112,52 +112,19 @@
 lier
-;%0Aimport com.github.peterpaul.cli.fn.Supplie
+.catchingFo
 r;%0A%0A
@@ -476,142 +476,25 @@
 urn 
-ExceptionCatchingSupplier.catchingFor(new Supplier%3CT%3E() %7B%0A            @Override%0A            public T supply() %7B%0A                return
+catchingFor(() -%3E
  ser
@@ -527,33 +527,33 @@
 tantiate(aClass)
-;
+)
 %0A            %7D%0A 
@@ -547,30 +547,22 @@
         
-  %7D%0A
       
-  %7D)
 .supply(
@@ -566,131 +566,41 @@
 ly()
-.orElseGet(new java.util.function.Supplier%3CT%3E() %7B%0A            @Override%0A            public T g
+%0A                .orElseG
 et(
+(
 ) 
-%7B%0A                return
+-%3E
  cla
@@ -637,33 +637,8 @@
 ass)
-;%0A            %7D%0A        %7D
 );%0A 

Replace anonymous instances with lambdas.