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");
}
}
この埋め込み注釈の概念がまったく可能な場合は? それとも似たようなもの?