From: Kevin B. <kb...@ca...> - 2002-01-19 00:21:21
|
Samuele Pedroni wrote: > > def adapt(listenerClass, **bindings): > global _adapt_u > _adapt_u +=1 > return new.classobj("_%s" % _adapt_u,( listenerClass,),bindings)() [snip] > >>> b=JButton("Ok",actionListener=adapt(ActionListener,actionPerformed=doIt)) I like it. :-) Could we even go one step further, and make the __init__ method for a Java Interface be something very like 'adapt'? (The current __init__ behavior (throw TypeError) is not generally useful.) This would allow a nicer syntax: >>> b=JButton("Ok",actionListener=ActionListener( actionPerformed=doIt )) And would facilitate anonymous classes for other non-Event uses (which I've wanted before, but can't think of examples right now!) kb |