可以“主要”在java中返回一个String? [英] Can "main" in java return a String?

查看:104
本文介绍了可以“主要”在java中返回一个String?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java中的public static void main(String [] args)是否可能返回 String 而不是 void ?如果有,怎么样?

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)

而不是:

    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;


}

我收到此错误:

   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)


推荐答案

简而言之 - 否,它不能。
您始终可以从main方法打印到stdout(使用 System.out.print System.out.println ),但你不能改变 main 的返回类型。

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.

这篇关于可以“主要”在java中返回一个String?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆