在Java中,public static void main(String[] args)返回的是void类型,而不是String类型。如果想要让它返回String类型,需要将void替换为String,并在方法内部添加return语句来返回一个字符串。
public static String main(String[] args)
替代:
public static void main(String[] args)
当我将我的代码修改如下:
当我将我的代码修改为以下内容:
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)