gpt4 book ai didi

java - SonarLint,字符串数组 : Declare this local variable with "var" instead = error

转载 作者:行者123 更新时间:2023-12-03 20:00:25 24 4
gpt4 key购买 nike

Java 11 ,对于这段代码:

String[] arrayString = {"foo", "bar"};
SonarLintDeclare 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 - SonarLint,字符串数组 : Declare this local variable with "var" instead = error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67470860/

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