2

相同的代码在 IDE 中工作,但在 Cmd Line 中没有。这是我的代码。我找不到错误是什么?

import java.util.*;
import java.lang.*;

public class AppendingBuffer{
    public static void main(String[] args){
        StringBuilder sb;
        sb = new StringBuilder("abc");
        sb.append("def").reverse().insert(3, "---");
        System.out.println(sb);
    }
}

此处的两个屏幕截图显示了 IDE 和 Cmd 行程序。

命令行错误:

E:\java\6>javac AppendingBuffer.java
AppendingBuffer.java:7: error: constructor StringBuilder in class StringBuilder
cannot be applied to given types;
                sb = new StringBuilder("abc");
                     ^
  required: no arguments
  found: String
  reason: actual and formal argument lists differ in length
AppendingBuffer.java:8: error: cannot find symbol
                sb.append("def").reverse().insert(3, "---");
                  ^
  symbol:   method append(String)
  location: variable sb of type StringBuilder
.\StringBuilder.java:5: error: constructor StringBuilder in class StringBuilder
cannot be applied to given types;
                StringBuilder sb = new StringBuilder("abc");
                                   ^
  required: no arguments
  found: String
  reason: actual and formal argument lists differ in length
.\StringBuilder.java:6: error: cannot find symbol
                sb.append("def").reverse().insert(3, "---");
                  ^
  symbol:   method append(String)
  location: variable sb of type StringBuilder
4 errors

E:\java\6>

Java 命令行 Java 集成开发环境

4

1 回答 1

7

您可能在类路径上有另一个类StringBuilder。在尝试重新编译之前重命名本地源文件或将其完全删除。

于 2013-07-01T14:19:07.283 回答