Hacker News new | past | comments | ask | show | jobs | submit login

The problem is with

    interface FooBar extends Foo, Bar {}
FooBar can be defined in a library that you can't change. The solution in Java 8 would be using default methods:

    interface Foo extends FooBar {
        default int bar() { throw new UnsupportedOperationException(); }
    }
And then you can even do the other trick mentioned in the article even more easily:

    Foo f = () -> 3;
And f now satisfies FooBar, by throwing an exception when bar is called, and returning 3 when foo is called.

But, assuming method

    void doSomething(FooBar x) { ... }
you can't call it like this:

    doSomething(() -> 3);
What you can do is call it like this:

    doSomething((Foo)() -> 3);



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: