...
> Where does JLS say the class should be public? I failed to find it in
> the index and in the following page that explains how a program is
> executed.
I don't remember ever seeing any suggestion that the class has to be public
either. Section 12.1.4 of the JLS states what that the main(String[]) method
must be public, static, and void, but makes no mention of conditions that the
class itself must meet.
In any case, it's far from clear that that section is intended to be
normative -- it is embedded in a whole sequence of text which is clearly
descriptive rather than normative (and which explicitly references the JVM
spec, describing itself as "an overview"). In my opinion, whether or not it
is /intended/ to be normative, it damn-well /shouldn't/ be normative as
written; because if it was it would be requiring a behaviour that no complete
Java implementation has ever exhibited, nor ever will. The public static void
main(String[]) thing is just how one way of launching Java programs works -- it
is incidental to that specific program, and other programs can and do work in
different ways. That has been true ever since JDK 1.0.2, and probably before.
FWIW, the code for the java.exe launcher is simple, and it would be trivial to
add a check that the entry-point class is public (and perhaps that it's a
top-level class too). Similar trivial code already exists only a few lines
away to ensure that main() is public. So, if this is a bug, there hardly seems
to be a plausible reason for it to have remained unfixed for so long.
-- chris
Jussi Piitulainen - 04 Apr 2007 12:53 GMT
>> Where does JLS say the class should be public? I failed to find it
>> in the index and in the following page that explains how a program
[quoted text clipped - 4 lines]
> main(String[]) method must be public, static, and void, but makes no
> mention of conditions that the class itself must meet.
Yes, it's quite explicit about _main_ being _public static void_, and
seems, to me, quiet about the class (other than actually using the now
allegedly forbidden form as example code).
As of now, I suspect the allegation upthread was mistaken.
>>>>> class Just
>>>>> {
[quoted text clipped - 13 lines]
>
> <http://java.sun.com/docs/books/jls/third_edition/html/execution.html#44444>
I just checked. You are rigth. I must have messed up class and method.
Arne
Jussi Piitulainen - 05 Apr 2007 12:00 GMT
>>>>>> class Just
>>>>>> {
>>>>>> public static void main(String[] args)
>> ...
>>>> Doesn't the class need to be public?
>>> It should according to JLS.
...
>> Where does JLS say the class should be public? I failed to find it in
>> the index and in the following page that explains how a program is
...
> I just checked. You are rigth. I must have messed up class and
> method.
Thanks.