java代码块注释_如何在Java中注释代码块

2023-05-16

是否可以注释一段代码?例如.循环或简单的花括号?如果是这样,怎么样?

First.java

package An;

import An.ForCycle;

class First {

public static void main(String[] args) {

First f = new First();

}

public First () {

@ForCycle

{ // error: illegal start of type {

int k;

}

@ForCycle

for (int i = 0; i < 5; i++) { // similar error (illegal start...)

System.out.println(i);

}

}

}

ForCycle.java

package An;

import java.lang.annotation.Documented;

import java.lang.annotation.ElementType;

import java.lang.annotation.Retention;

import java.lang.annotation.RetentionPolicy;

import java.lang.annotation.Target;

@Retention(RetentionPolicy.SOURCE)

public @interface ForCycle {}

@Target – indicates the kinds of program element to which an annotation type is applicable. Some possible values are TYPE, METHOD, CONSTRUCTOR, FIELD etc. If Target meta-annotation is not present, then annotation can be used on any program element.

任何程序元素(我猜)也意味着阻止,不是吗?那么为什么我不能注释阻止或为?我错过了什么?

感谢帮助

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java代码块注释_如何在Java中注释代码块 的相关文章

随机推荐