gpt4 book ai didi

java - 尝试返回一个字符串数组

转载 作者:行者123 更新时间:2023-12-01 07:35:16 26 4
gpt4 key购买 nike

我已经写了这个方法,但不确定为什么会出现错误。我对编程还很陌生,所以有人认为这有什么明显的错误吗?

public String[] gen() {
String big = "A";
String small = "a";
return String[] {big, small};
}

注意:在return String[]下获取红线

最佳答案

更改为

public String[] gen() {

String big = "A";
String small = "a";
return new String[] {big, small};

}

String[]{String, String} //is not a valid array constructor,

相反,你应该使用

new String[]{String, String} constructor.

关于java - 尝试返回一个字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com