C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet>dir Volume in drive C has no label. Volume Serial Number is 2041-64E7 Directory of C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet 2009-07-02 23:54 . 2009-07-02 23:54 .. 2004-09-06 14:57 582 WelcomeApplet.html 2004-09-06 15:04 1,402 WelcomeApplet.java 2 File(s) 1,984 bytes 2 Dir(s) 2,557,210,624 bytes free C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet>javac WelcomeApplet.java C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet>dir Volume in drive C has no label. Volume Serial Number is 2041-64E7 Directory of C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet 2009-07-02 23:54 . 2009-07-02 23:54 .. 2009-07-02 23:54 975 WelcomeApplet$1.class 2009-07-02 23:54 1,379 WelcomeApplet.class 2004-09-06 14:57 582 WelcomeApplet.html 2004-09-06 15:04 1,402 WelcomeApplet.java 4 File(s) 4,338 bytes 2 Dir(s) 2,557,202,432 bytes free C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet>
这是该Java文件的内容:
/** @version 1.21 2002-06-19 @author Cay Horstmann */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.*; public class WelcomeApplet extends JApplet { public void init() { setLayout(new BorderLayout()); JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER); label.setFont(new Font("Serif", Font.BOLD, 18)); add(label, BorderLayout.CENTER); JPanel panel = new JPanel(); JButton cayButton = new JButton("Cay Horstmann"); cayButton.addActionListener(makeURLActionListener( "http://www.horstmann.com")); panel.add(cayButton); JButton garyButton = new JButton("Gary Cornell"); garyButton.addActionListener(makeURLActionListener( "mailto:gary@thecornells.com")); panel.add(garyButton); add(panel, BorderLayout.SOUTH); } private ActionListener makeURLActionListener(final String u)
这些是.class保存匿名内部类的文件。
.class
在你的示例中,WelcomeApplet.java包含一个顶级类(称为WelcomeApplet)和一个匿名内部类,它们将存储在中WelcomeApplet$1.class。
WelcomeApplet.java
WelcomeApplet
WelcomeApplet$1.class
请注意,包含匿名内部类的文件的确切名称尚未标准化,并且可能会有所不同。但是实际上,除了这里描述的方案之外,我还没有看到其他方案。
的值特定主体enum也是匿名内部类:
enum
枚举常量的可选类主体隐式定义了一个匿名类声明(第15.9.5节),该声明扩展了直接封闭的枚举类型。