Jer*_*ren 6 java string return
是否有可能java中的public static void main(String [] args)返回String而不是void?如果有,怎么样?
public static String main(String[] args)
Run Code Online (Sandbox Code Playgroud)
代替:
public static void main(String[] args)
Run Code Online (Sandbox Code Playgroud)
当我更改我的代码如下:
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;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
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)
Run Code Online (Sandbox Code Playgroud)
简而言之 - 不,它不能.您始终可以从main方法(使用System.out.print或System.out.println)打印到stdout ,但不能更改返回类型main.
| 归档时间: |
|
| 查看次数: |
13454 次 |
| 最近记录: |