From virtual extension methods to mixins
Brenden Towey
brendentowey at gmail.com
Mon Jul 9 09:26:43 PDT 2012
You're probably aware of this, but the corollary is "a lot of folks
would really like multiple inheritance," diamond problem or no.
Just for the heck of it, here's my cheap-hack wish for a future Java
extension (no pun intended). Allow inherited interfaces to be delegated
to a particular field variable. For example,
class MyWidget extends MyOtherWidget implements Map(aField) {
HashMap aField = new HashMap();
}
Here the compiler should generate all the methods in Map, and delegate
them to the object in aField. If you don't want to do that, just
override any given method normally. Those methods won't be delegated.
Probably anyone could find problems with this idea, but it's a LOT
briefer than having to wade though a ton of simple delegation methods
when you're reading somebody else's code. OK going back to lurk mode
now....
On 7/9/2012 4:50 AM, Brian Goetz wrote:
> Please don't encourage techniques like this. There are a zillion "clever" things you can do in Java, but shouldn't. We knew it wouldn't be long before someone suggested this, and we can't stop you. But please, use your power for good, and not for evil. Teach people to do it right, not to abuse it.
>
>
> On Jul 9, 2012, at 1:12 AM, François Sarradin wrote:
>
>> Hi,
>>
>> I would like to share a blog post. It explains how to get multiple
>> inheritance of the state from the virtual extension methods.
>>
>> "Java 8: Now You Have Mixins!" =>
>> http://kerflyn.wordpress.com/2012/07/09/java-8-now-you-have-mixins/
>>
>> François-
>>
>
More information about the lambda-dev
mailing list