允许 Java 注释的语义将它们放置在某处在函数体内,例如注释特定的函数调用、语句或表达式?
例如:
class MyClass {
void theFunc(Thing thing) {
String s = null;
@Catching(NullPointerException) //<< annotation ?
s = thing.getProp().getSub().getElem().getItem();
if(s==null)
System.out.println("null, you fool");
}
}
缩写经常写的(太频繁了,绝对!):
class MyClass {
void theFunc(Thing thing) {
String s = null;
try {
s = thing.getProp().getSub().getElem().getItem();
} catch(NullPointerException ex) { }
if(s==null)
System.out.println("null, you fool");
}
}
如果这个概念嵌入注释有可能吗?或者类似的东西?
元素类型 http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/ElementType.html指定注释的有效目标。您无法注释任何旧语句。它基本上缩小到声明;声明:
- 注释类型
- 构造函数
- field
- 局部变数
- method
- package
- 范围
- type
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)