title: Can I use AspectJ to "wrap" a field with ThreadLocal?
body: <p>Let's say we have a class which looks like the following.</p>
  
  <pre><code>public class MyClass {
  
     @ThreadScoped    
     private Collection&lt;String&gt; words = new ArrayList&lt;String&gt;();
  
     public void addWord(String word) {
          words.add(word);
     }
  
  }
  </code></pre>
  
  <p>In runtime, we only have a single instance of this class, but it accepts calls from multiple threads.</p>
  
  <p>I want the developer who writes the class to be able to ignore the fact that they're writing it for multi-thread access and just annotate the field as "thread scoped".</p>
  
  <p>Is it possible to create an aspect which makes each calling thread have its own collection of words, as if the words field would have been a <code>ThreadLocal</code>? The collection should be tied to the thread even over multiple invocations of the method.</p>
  
  <p>I have seen the <code>set</code> and <code>get</code> point cuts, but cannot figure out a way to make use of them that would not require me to set the field on the object, which would ruin the thread safety of the class.</p>
  
  <p>Is there perhaps another way to do that which does not make use of aspects, such as with proxies or reflection?</p>