Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are auxiliary classes?

Tags:

java

class

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?

Edit: 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.

Edit 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
like image 938
BrainStorm.exe Avatar asked Mar 20 '14 00:03

BrainStorm.exe


People also ask

What is an auxiliary class in Java?

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.

What is abstract class in Active Directory?

An abstract class, which is a template used to derive new abstract, auxiliary, and structural classes. An abstract class can only be a subclass of an abstract class. Abstract classes cannot be instantiated in Active Directory Domain Services.


2 Answers

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 class can't be public and is not visible outside this AClass.java file.

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

Edit: 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

like image 51
Artem Avatar answered Sep 26 '22 20:09

Artem


An auxiliary class isn't any kind of official or technical thing as far as I know. Someone might describe a class as auxiliary if it were addressing a secondary concern, or something, but the compiler doesn't have any idea what an auxiliary class is, and neither do I.

In general, if you have error messages from the computer, please paste them in their entirety. If you think the compiler is upset about an auxiliary class, paste the error message: someone else will be able to make sense of it, whereas currently it's being filtered through some kind of confusion that's made you think auxiliary classes are a real thing!

like image 21
amalloy Avatar answered Sep 26 '22 20:09

amalloy