java - Groovy - Main method placement -
here code:
class cat {} class dog { static void main(string[] args) {} }
when compiled groovy says not have main method. when rid of cat class:
class dog { static void main(string[] args) {} }
its valid. thought, long had main method in any class code valid, wrong. can explain why can not have more 1 class when main method resides in 1 of classes?
you can have more 1 class, class defined first has have main method implementation. when run script, script executed in run()
method.
in case have class defined, name of class used name of script. in case there more 1 public class, runnable implementation has part of first defined class. below should work:
class dog { static void main(string[] args) { println "hello" } } class cat {}
you can clear picture when inspect ast in groovy console.
Comments
Post a Comment