java编程思想第4版中文版的几处谬误?

pdf143正常页142
代码

class Cleanser {
    private String s = new String("Cleanser");

    public void append(String a) {
        s += a;
    }

    public void dilute() {
        append(" dilute()");
    }

    public void apply() {
        append(" apply()");
    }

    public void scrub() {
        append(" scrub()");
    }

    public void print() {
        System.out.println(s);
    }

    public static void main(String[] args) {
        Cleanser x = new Cleanser();
        x.dilute();
        x.apply();
        x.scrub();
        x.print();
    }
}

public class Detergent extends Cleanser {
    // Change a method:
    public void scrub() {
        append(" Detergent.scrub()");
        super.scrub(); // Call base-class version
    }

    // Add methods to the interface:
    public void foam() {
        append(" foam()");
    }

    // Test the new class:
    public static void main(String[] args) {
        Detergent x = new Detergent();
        x.dilute();
        x.apply();
        x.scrub();
        x.foam();
        x.print();
        System.out.println("Testing base class:");
        Cleanser.main(args);
    }
}

“同“+”一样,“+=”被Java 用于对字串进行“过载”处理。"过载这个词让人看不懂
pdf144正常页143
错误的话(原文)
“需要着重强调的是Cleanser 中的所有类都是public 属性。”应该是Cleanser里的方法吧
“注意Cleanser 在它的接口中含有一系列方法:append(),dilute(),apply(),scrub()以及print()。”Cleanser是类不是接口吧

阅读 3.4k
3 个回答

书翻译的不准确,没了!

这么明显的问题,明明都知道……

非要别人给你确认一下,你才有自信认为是书的问题而不是自己的问题么?

英文原文(169页)是:

It's important that all of the methods in Cleanser are public.

至于第一个问题,原文(168页)是:

First, in the Cleanser append() method, Strings are concatenated to s using the += operator, which is one of the operators (along with '+') that the Java designers "overloaded" to work with Strings.

翻译的不恰当,应该翻译为“重载”
如果了解C++的话,就知道这个相当于String类对“+=”操作符进行了重新实现,“+=”可以用来进行字符串拼接。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题