package com.example; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.Future; import java.util.function.Function; abstract class ImmutableMap implements Map { public static Builder builder() { return new Builder<>(); } public static class Builder { public Builder put(K key, V value) { throw new UnsupportedOperationException(); } public ImmutableMap buildOrThrow() { throw new UnsupportedOperationException(); } } } interface Staircase {} interface ListenableFuture extends Future { void addListener(Runnable listener, Executor executor); } interface Hesitate extends ListenableFuture {} final class Provision implements Staircase {} final class Charter implements Staircase {} final class Professor implements Staircase {} final class Twilight implements Staircase {} final class Residence implements Staircase {} final class Salad {} final class Science implements Staircase { public Professor getProfessor() { throw new UnsupportedOperationException(); } public Charter getCharter() { throw new UnsupportedOperationException(); } public Twilight getTwilight() { throw new UnsupportedOperationException(); } public Residence getResidence() { throw new UnsupportedOperationException(); } } interface Sketch { Hesitate strengthen(Salad s, Professor p); Hesitate supervise(Salad s, Twilight t); } enum City { LARGE_CITY, SMALL_CITY } final class MyClass { public void foo() { ImmutableMap> local = ImmutableMap .> builder() .put( City.LARGE_CITY, new CityEndorser<>( Science::getProfessor, Science::getCharter, s -> s::strengthen)) .put( City.SMALL_CITY, new CityEndorser<>( Science::getTwilight, Science::getResidence, // Exception on getFunctionalInterfaceType() of the lambda expression. s -> s::supervise)) .buildOrThrow(); } private interface Manufacturer { Hesitate go(Salad s, Q q); } private static class CityEndorser { private CityEndorser( Function qExtractor, Function pExtractor, Function> m) {} } }