tow*_*owi 6 java annotations exception
允许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");
}
}
Run Code Online (Sandbox Code Playgroud)
缩写经常写的(经常,绝对!):
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");
}
}
Run Code Online (Sandbox Code Playgroud)
如果这个嵌入式注释的概念可行呢?或类似的东西?
| 归档时间: |
|
| 查看次数: |
2107 次 |
| 最近记录: |