Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can "main" in java return a String?

Is it possible that public static void main(String[] args) in java returns String instead of void? If yes, how?

public static String main(String[] args)

instead of:

public static void main(String[] args)

when I change my code as below:

public static String main(String[] args) throws IOException {
    String str = null;
    TurkishMorphParser parser = TurkishMorphParser.createWithDefaults();
    str = new Stm(parser).parse("bizler");
    System.out.println("str = " + str);
    String replace = str.replace("[","");
    String replace1 = replace.replace("]","");
    List<String> result1 = new ArrayList<String>(Arrays.asList(replace1.split(",")));
    String result = result1.get(0);
    System.out.println("Result = " + result);
    return result;        
}

I receive this error:

Error: Main method must return a value of type void in class Stm, please define the main method as:
public static void main(String[] args)
like image 576
Jeren Avatar asked May 25 '14 15:05

Jeren


1 Answers

In short - no, it can't. You can always print to stdout from the main method (using System.out.print or System.out.println), but you can't change the return type of main.

like image 82
Mureinik Avatar answered Sep 22 '22 18:09

Mureinik