有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java中的嵌套注释

我想知道我怎样才能写出这样的东西:

this comment */ ends here

在java的注释中。我在网上搜索了一个小时,没有结果。如果我写:

/* this comment */ ends here */ 

然后注释将在第一个*/结束。 注意,我想使用/* */注释,而不是//注释。 谢谢


共 (5) 个答案

  1. # 1 楼答案

    因为*/对语言有价值,所以你需要处理*/使之与众不同。 你能说

    this comment * / ends here
    

    或者

    this comment *\ ends here
    
  2. # 2 楼答案

    /**/comment样式绝对需要两个字符对。它不允许结束字符对,除非在注释末尾。我能回答的最接近我想你问的问题是:

    /* this comment */
    /* ends here */
    
  3. # 3 楼答案

    不可以。不能在用/*打开的注释中嵌入*/注释。当遇到第一个*/时,注释关闭

  4. # 4 楼答案

    /* this comment */// ends here */
    
    /* this comment *//* ends here */
    
    /* this comment */ /* ends here */
    
  5. # 5 楼答案

    可以这样做:

    /** this comment */ ends here */
    

    *是*的HTML字符代码,当注释被处理成文档时,只剩下*了

    例如:

    enter image description here