🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #14448

Question about strange new operator syntax

#14448
From: A. Florentin
Date: Tue, 31 Aug 1999 00:00
46 lines
1520 bytes
I am new to Java, but have been programming in C++ for years.

I have seen code like the following in two or three places. Please explain
it:


public class X extends Frame {

// various

public static void main(String[] args) {

// what is this doing? (I mean syntactically)
WindowListener l = new WindowAdapter() {
   public void windowClosing(WindowEvent e) {
       System.exit(0);
   }
};

// etc

}

I understand that WindowAdapter is an
abstract class that implements WindowListener.

It looks as though the block after the new operator
redefines one of the WindowAdapter methods, as needed by the program.  This
looks like very strange syntax to me. It should be something like:

class MyWindowAdapter extends WindowAdapter {
   public void windowClosing(WindowEvent e) {
          System.exit(0);
   }
}

And then:

WindowListener l = new MyWindowAdapter();


Can someone please explain?

TIA

Alberto
Technical Details
Message-ID: <7qf634$4a8$1@uk21.supernews.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,eef714514d3081c4,start
X-Google-Attributes: gidf74b3,public
From: "A. Florentin" <albertos@spidernet.com.cy>
Subject: Question about strange new operator syntax
Date: 1999/08/31
Message-ID: <7qf634$4a8$1@uk21.supernews.com>
X-Deja-AN: 519086429
X-Trace: 936057764 HBCTSYEEA882AC29A uk21.supernews.com
Organization: RemarQ http://www.remarQ.com
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Newsgroups: borland.public.jbuilder.java.language
X-Complaints-To: newsabuse@remarq.com