小编Kik*_*iko的帖子

Java中简单String对象的错误

我正在尝试编译以下代码:

public class Test {

    public static void main(String[] args) {
        String final = new String("");
        final = "sample";
        System.out.println(final);
    }
}
Run Code Online (Sandbox Code Playgroud)

显然,编译器向我显示以下错误:

Test.java:5: error: not a statement
    String final = new String("");
    ^
Test.java:5: error: ';' expected
    String final = new String("");
          ^
Test.java:5: error: illegal start of type
    String final = new String("");
                 ^
Test.java:6: error: illegal start of type
    final = "sample";
          ^
Test.java:7: error: illegal start of expression
    System.out.println(final);
                       ^
Test.java:7: error: illegal start of type …
Run Code Online (Sandbox Code Playgroud)

java string declaration declare

2
推荐指数
1
解决办法
105
查看次数

标签 统计

declaration ×1

declare ×1

java ×1

string ×1