> final mouse = MouseAdapter.new {
> method mousePressed( event ) {
> if ( !event.isPopupTrigger ) { return }
> ...
> }
> method mouseReleased( event ) {
> if ( !event.isPopupTrigger ) { return }
> ...
> }
> };
> panel.addMouseListener mouse;
> or
> panel.addMouseListener new {
> method mousePressed( event ) {
> if ( !event.isPopupTrigger ) { return }
> ...
> }
> method mouseReleased( event ) {
> if ( !event.isPopupTrigger ) { return }
> ...
> }
> };
What I would normally code, is the following. I have a NB editor 'code template' that expands this text and leaves the cursor at the ${name} point. Tab switches to ${comp} and another tab switches to ${cursor}
panel.addMouseListener( new MouseAdapter() {
public void mousePressed( MouseEvent ev ) {
if( ev.isPopupTrigger() ) { showPopup(ev); }
}
public void mouseReleased( MouseEvent ev ) {
if( ev.isPopupTrigger() ) { showPopup(ev); }
}
private void showPopup( MouseEvent ev ) {
JPopupMenu pop = new JPopupMenu();
JMenuItem mi = new JMenuItem(${name});
${cursor}
pop.show( ${comp}, ev.getX(), ev.getY() );
}
});
In total, I don't see any change in the readability. It might be just a few more characters to type, but that's not gonna put millions in the bank directly.
> This is a good example of how the proposal simplifies things.
> interface TwoMethodsTwoExceptions {
> method< Throwable... T1s > void method1( boolean which ) throws T1s;
> method< Throwable... T2s > void method2( boolean which ) throws T2s;
> }
> In current Java the above is roughly (only two
> exceptions):
> interface TwoMethodsTwoExceptions {
> < T1A extends Throwable, T1B extends Throwable > void method1( boolean which ) throws T1A, T1B;
> < T2A extends Throwable, T2B extends Throwable > void method2( boolean which ) throws T2A, T2B;
> }
There are some new capabilities here, in the form of the elipses designation of multiple, similar type parameters. There is some benefit in terms of expressivity.
But, I'm troubled by the notion that the compiler would have to assume 'throws Throwable' or whatever super class was specified. The interface declaration could just as well say "throws Throwable" and move on.