groovy

Cannot have a script with a main method as the starting point

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.7-beta-1
  • Fix Version/s: 1.7-beta-2, 1.6.6
  • Component/s: Compiler
  • Labels:
    None
  • Environment:
    Groovy Version: 1.7-beta-2-SNAPSHOT JVM: 1.5.0_06 (Windows XP)
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

Can a groovy script not provide its main() method?

Case 1: If I run the following script, nothing happens:

static main(args) {
    println "Roshan"
}

Doing a javap on the generated class, I see it now has duplicate definitions of main(), as:

public static void main(java.lang.String[]); // groovy generated
public static java.lang.Object main(java.lang.String[]); // one provided in the script

In the above script nothing is happening because groovy invokes its own main(), which is effectively empty here.

Case 2: If I change the script to:

static void main(args) {
    println "Roshan"
}

then it fails saying

Repetitive method name/signature for method 'void main(java.lang.Object)' in class 'Try'.

So, there is no way I can write a script that has main() as the starting point.

First case produces an invalid class and second case also does not allow the user to provide his own main() starting point.

Activity

Hide
Roshan Dawrani added a comment -

After GROOVY-3801 fix, case 1 also generates the "main" method with correct signature, so both case 1/2 examples now result in the same error - Repetitive method name/signature for method 'void main(java.lang.Object)' in class 'Try'.

Show
Roshan Dawrani added a comment - After GROOVY-3801 fix, case 1 also generates the "main" method with correct signature, so both case 1/2 examples now result in the same error - Repetitive method name/signature for method 'void main(java.lang.Object)' in class 'Try'.
Hide
Roshan Dawrani added a comment -

Fixed

Show
Roshan Dawrani added a comment - Fixed

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: