什么是辅助类? [英] What are auxiliary classes?

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

问题描述

我知道这些问题可能听起来很蠢,但在Java中,什么是辅助类,一些人如何编写一个,以及编译器如何知道某个东西是辅助类?

I know these questions may sound stupid, but in Java, what are Auxiliary classes, how does some one write one, and how does the compiler know that something is an Auxiliary class?

编辑:
我问这是因为编译器生成一个关于外部库中的对象的警告,我想知道为什么。

The reason I ask this is because the compiler is generating a warning regarding an object in an external library, and I want to know why.

编辑2:

这是编译器警告那些想要它的人:

Here is the compiler warning for those who want it:

warning: auxiliary class Pattern in jregex/Pattern.java should not be accessed from outside its own source file


推荐答案

如Java规范此处,您可以在一个.java文件中指定多个类。类名与.java文件名匹配的类将是可以声明为public并且对其他类可见的主类。因此,文件中的所有其他类都是辅助类。辅助类不能被声明为public和(因为@trashgod正确地指出),因此它们只能用package-private访问声明。例如对于AClass.java文件:

As descried in Java specification here, you can specify more than one class in one .java file. The class which name matches .java file name will be the main class which can be declared public and be visible to other classes. All other classes in the file therefore are "auxilary" classes. Auxilary class can NOT be declared public and (as @trashgod rightfully pointed out) therefore they only be declared with package-private access. For instance for AClass.java file:

public class AClass {
    private AuxilaryClass a;
}
class AuxilaryClass {
    private int b;
}

AuxilaryClass类不能是public的,并且在此AClass.java之外不可见文件。

AuxilaryClass class can't be public and is not visible outside this AClass.java file.

但是,使用辅助类视为极差风格,而 Java代码约定。请使用单独的或 inner < a> class如果真的需要。

However, using auxilary classes considered extremely bad style and against Java Code Convention. Please use separate or inner classes if really needed.

编辑:术语辅助不是Oracle / Sun官方术语。它已在此处介绍(或使用): http://www.youtube.com/watch?v = miTM9rY3He0 和/或此处: http://doc.sumy。 ua / prog / java / langref / ch05_03.htm

The term "Auxilary" is not Oracle/Sun official terminology. It has been introduced (or used) here: http://www.youtube.com/watch?v=miTM9rY3He0 and/or here: http://doc.sumy.ua/prog/java/langref/ch05_03.htm

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

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