SonarLint,字符串数组:用 "var" 代替 = 错误声明此局部变量
SonarLint, Array of String: Declare this local variable with "var" instead = error
使用 Java 11
,对于此代码:
String[] arrayString = {"foo", "bar"};
SonarLint
说 Declare this local variable with "var" instead.
所以,我试过了:
var arrayString = {"foo", "bar"};
// or
var[] arrayString = {"foo", "bar"};
但现在我得到了这些错误:
Array initializer needs an explicit target-type
'var' is not allowed as an element type of an array
如何正确声明数组变量或属性。
你可以使用
var arrayString = new String[]{"foo", "bar"};
使用 Java 11
,对于此代码:
String[] arrayString = {"foo", "bar"};
SonarLint
说 Declare this local variable with "var" instead.
所以,我试过了:
var arrayString = {"foo", "bar"};
// or
var[] arrayString = {"foo", "bar"};
但现在我得到了这些错误:
Array initializer needs an explicit target-type
'var' is not allowed as an element type of an array
如何正确声明数组变量或属性。
你可以使用
var arrayString = new String[]{"foo", "bar"};