Comments

Comments

注释

Comments in Java, like comments in most programming languages, do not show up in the executable program. Thus, you can add as many comments as needed without fear of bloating the code. Java has three ways of marking comments. The most common method is a //. You use this for a comment that will run from the // to the end of the line.

Java中的注释像大多数编程语言的注释一样,并不会在可执行程序中出现。因此,你可以需要多少注释就加多少,而不用担心使代码过于臃肿。Java有三种标记注释的方式。最普通的方法是用//。你用它作注释时,从//一直到这一行的结尾都会被当作注释处理。

System.out.println("We will not use 'Hello, World!'"); // is this too cute?

 

When longer comments are needed, you can mark each line with a //. Or you can use the /* and */ comment delimiters that let you block off a longer comment. This is shown in.

当你需要比较长的注释时,可以在每一行的开头用//来标记。或者你可以用注释分隔符/**/来分隔较长的注释。如Example 3-1所示。

Example 3-1. FirstSample.java

 1. /*

 2.    This is the first sample program in Core Java Chapter 3

 3.    Copyright (C) 1997 Cay Horstmann and Gary Cornell

 4. */

 5.

 6. public class FirstSample

 7. {

 8.    public static void main(String[] args)

 9.    {

10.       System.out.println("We will not use 'Hello, World!'");

11.    }

12. }

 

Finally, a third kind of comment can be used to generate documentation automatically. This comment uses a /** to start and a */ to end. For more on this type of comment and on automatic documentation generation, see Chapter 4.

最后,第三种注释方式可以被用来自动生成文档。这种注释以/**开头,以*/结尾。关于这种注释方式及自动生成文档的更多信息,参见第4章。

CAUTION

/* */ comments do not nest in Java. That is, you cannot deactivate code simply by surrounding it with /* and */ because the code that you want to deactivate might itself contain a */ delimiter.

Java中的/* */注释不能嵌套。也就是说,你不能通过直接用/**/把代码围起来的办法使它失效,因为你打算围起来的这段代码本身可能就包含有*/分隔符。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值