info-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OT: Java filenames and classes


From: Mark A. Flacy
Subject: OT: Java filenames and classes
Date: Thu, 28 Feb 2002 23:25:17 -0600

>>>>> "Noel" == Noel Yap <address@hidden> writes:
Noel> 
Noel> The following output suggests otherwise:
Noel> 
Noel> nyap:address@hidden:~/proj/asdf> cat Asdf.java
Noel> public class Aoeu
Noel> {
Noel>         public static void main(String[] args)
Noel>         {
Noel>                 System.out.println("Yo");
Noel>         }
Noel> }
Noel> nyap:address@hidden:~/proj/asdf> javac -classpath .
Noel> Asdf.java
Noel> Asdf.java:1: class Aoeu is public, should be declared
Noel> in a file named Aoeu.java
Noel> public class Aoeu
Noel>        ^
Noel> 1 error
Noel> 
Noel> Am I missing something here?  Is there a flag to make
Noel> this error into a warning?
Noel> 
Noel> If there isn't, I think the "should" in the warning
Noel> should be changed to "must".

I sit partially corrected.

A public class must sit in a file that matches the classname.  A package
level class does not.  The directory where the source resides does not have
to match in any fashion the package statement included in the source file.

FWIW, in java 1.2.2 the error message contained "...must be defined in a
file..." 

So yes, you cannot willy-nilly stick all of your java source in files whose
names have no connection to the classes defined within.  You can, however,
do so with package level classes.  You can also place all of those files in
any directory structure that you wish; however any autodependency stuff
will not work in that case.  


-- 
 Mark A. Flacy   Architect Weasel CS3K Solution OAM&P, Group B824 
 address@hidden   (972) 685-8347  (ESN) 445-8347
 Any opinions expressed above are my own.  Any facts expressed above
 that you could detect means my weasel wording needs work.
"Engineering is the art of making what you want from things you can get."
  --Unknown




reply via email to

[Prev in Thread] Current Thread [Next in Thread]