Re:Go's power is in emergent behavior
by e12e on Sunday April 27, 2014 @01:49AM
(#7654124)
I suppose it might be "bad form", but couldn't you, if you had:
refactor FooBar to simply:
And keep FooBar the way it was, but now cast it to a Foo (or Bar) when you don't want a FooBar?
[ Parent
| on HN ]
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);