类文件名中的 $1 是什么? [英] What is the $1 in class file names?

查看:81
本文介绍了类文件名中的 $1 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C:Program FilesJavajdk1.6.0_05CoreJavav1v1ch2WelcomeApplet>dir
 Volume in drive C has no label.
 Volume Serial Number is 2041-64E7

 Directory of C:Program FilesJavajdk1.6.0_05CoreJavav1v1ch2WelcomeApplet

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 FilesJavajdk1.6.0_05CoreJavav1v1ch2WelcomeApplet>javac WelcomeApplet.java

C:Program FilesJavajdk1.6.0_05CoreJavav1v1ch2WelcomeApplet>dir
 Volume in drive C has no label.
 Volume Serial Number is 2041-64E7

 Directory of C:Program FilesJavajdk1.6.0_05CoreJavav1v1ch2WelcomeApplet

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 FilesJavajdk1.6.0_05CoreJavav1v1ch2WelcomeApplet>

这是该 Java 文件的内容:

Here is the content of that Java file:

/**
   @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)
   {
      return new
         ActionListener()
         {
            public void actionPerformed(ActionEvent event)
            {
               try
               {
                  getAppletContext().showDocument(new URL(u));
               }
               catch(MalformedURLException e) 
               { 
                  e.printStackTrace(); 
               }
            }
         };
   }
}

推荐答案

那些是 .class 文件,其中包含 匿名内部类.

Those are the .class files that hold the anonymous inner classes.

在您的示例中,WelcomeApplet.java 包含一个顶级类(称为 WelcomeApplet)和一个匿名内部类,该类将存储在 WelcomeApplet$1 中.类.

In your example WelcomeApplet.java contains a top-level class (called WelcomeApplet) and an anonymous inner class, which will be stored in WelcomeApplet$1.class.

请注意,保存匿名内部类的文件的确切名称未标准化,可能会有所不同.但在实践中,除了此处描述的方案之外,我还没有看到任何其他方案.

Note that the exact name of the files holding anonymous inner classes is not standardized and might vary. But in practice I've yet to see any other scheme than the one described here.

enum 的特定于值的主体 也是匿名内部类:

Value-specific bodies for an enum are also anonymous inner classes:

枚举常量的可选类主体隐式定义了一个匿名类声明(§15.9.5) 扩展了直接封闭的枚举类型.

The optional class body of an enum constant implicitly defines an anonymous class declaration (§15.9.5) that extends the immediately enclosing enum type.

这篇关于类文件名中的 $1 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆