存在しませんが、この構文に似たものを探しています。
コレクションに対してメソッドを動作させ、メソッドの存続期間中、コレクションが台無しにされないようにしたいと考えています。
したがって、次のようになります。
private void synchronized(collectionX) doSomethingWithCollectionX() {
// do something with collection x here, method acquires and releases lock on
// collectionX automatically before and after the method is called
}
しかし、代わりに、これを行う唯一の方法は次のとおりです。
private void doSomethingWithTheCollectionX(List<?> collectionX) {
synchronized(collectionX) {
// do something with collection x here
}
}
それが最善の方法ですか?