image-zho-CN-00-21

“哇,另一个人类女人!但这个人是黑头发。太令人兴奋了!”

“嗨,我叫金。”

“嗨,我叫阿米戈!”

“我知道。我为你取的名字。迭戈是不会想出这个名字的。”

阿米戈的思想以电子的速度飞奔起来。“嗯......她太好了......我不知道她是否喜欢机器人。”

“让我们回到课程上来。我将用简单的语言向你解释这些内容。”

“好的。”

“我想对教授和里希所说的话补充几句。”

“在 Java 语言中,你可以编写命令,但也可以在代码中为这些命令添加注释。编译器会完全忽略这些注释。当程序运行时,所有的注释都被忽略。

“请给我举个例子。”

“哦,当然可以:”

public class Home
{
    public static void main(String[] args)
    {
        /*
        Now we'll display the phrase 'Amigo Is The Best' on the screen
        */
        System.out.print("Amigo ");
        System.out.print("Is ");
        System.out.print("The ");
        System.out.print("Best");
    }
}    

“我们添加了‘现在我们将在屏幕上显示......’这一注释。该注释的开头应以一对(/*)符号来标记,而结尾用一对(*/)符号来标记。当编译程序时,编译器会忽略/*符号和*/符号之间的所有内容。

“这是否意味着我可以写任何我想写的东西?”

“是的。通常,代码中的注释内容是说明关于代码中难以理解的部分。有些注释由几十个字符串组成,通常写在一些方法的前面,以描述这些方法如何工作的细微差别。”

“还有一种方法可以为代码添加注释。你可以使用两个斜杠(//)。”

public class Home
{
    public static void main(String[] args)
    {
        System.out.print("Amigo ");
        System.out.print("Is The "); // This is also a comment
        System.out.print("Best");
    }
}

“在这里,// 符号开头和以 // 符号结尾的代码也被认为是注释。换句话说,没有使用第二对符号来‘完成注释’。”

“顺便说一句,有些注释真的很有趣。”

// I'm not responsible of this code. They made me write it, against my will.
// Dear future me. Please forgive me.
// I can't even begin to express how sorry I am.
// If I see something like this once more, I'll have a complete mental breakdown at work.
// If this condition is ever satisfied,
// please inform me for a reward. Phone: xxx-xxx-xxx.
// Dear maintainer:
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
// total_hours_wasted_here = 42
// When I wrote this, only God and I understood what I was doing
// Now, God only knows
// Sometimes I believe compiler ignores all my comments.
// I dedicate all this code, all my work, to my wife, Darlene, who will 
// have to support me and our three children and the dog once it gets 
// released into the public.
// Drunk, fix later
// Magic. Do not touch

“是的,有些注释非常好笑。”

“今天就讲到这里。”

“这堂课很短,但很有趣。谢谢,金。”