Running static main method inside abstract class, containing another main method
Remi Forax
forax at univ-mlv.fr
Mon Jan 20 18:43:08 UTC 2025
Hello,
wrong mailing list,
If you take a look to the header of JEP 495
[ https://openjdk.org/jeps/495 | https://openjdk.org/jeps/495 ]
the right mailing list is "amber dash dev at openjdk dot org"
regards,
Rémi
> From: "Mikhail Pyltsin" <pyltsinm at gmail.com>
> To: "compiler-dev" <compiler-dev at openjdk.org>
> Sent: Monday, January 20, 2025 7:35:31 PM
> Subject: Running static main method inside abstract class, containing another
> main method
> Hi!
> Sorry, I am not sure that it is a correct channel, but probably, it is related
> to jep specification.
> I am investigating a new version of jep495
> ( [
> https://cr.openjdk.org/~gbierman/jep495/jep495-20241101/specs/simple-source-files-instance-main-methods-jls.html#jls-12.1.3
> |
> https://cr.openjdk.org/~gbierman/jep495/jep495-20241101/specs/simple-source-files-instance-main-methods-jls.html#jls-12.1.3
> ] )
> and came up with such an example:
> ```java
> public abstract class AbstractClass {
> public static void main() {
> System.out.println("Hello, World!");
> }
> public void main(String[] args) {
> System.out.println("Hello, World! no constructor, non-static, args");
> }
> }
> ```
> Right now java chooses `void main(String[] args) ` because it contains argument,
> but cannot create this class, because it is abstract,
> I have got this error: `Exception in thread "main"
> java.lang.InstantiationException: AbstractClass`
> Could you help me if this is expected? I expect that `public static void main()`
> will be chosen.
> I cannot find anything related to this in JEP except this one:
> `The behavior of an implementation if there is no candidate method to invoke, or
> if there is no suitable constructor in the initial class when invoking an
> instance candidate method, is beyond the scope of this specification.', but it
> doesn't contain this case.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250120/d6d3d300/attachment.htm>
More information about the compiler-dev
mailing list