Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] instance tracking example in dev notebook

The instance tracking example in the developer's notebook at

  http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/ajdk15notebook/pertypewithin.html

is very cool, but it should use WeakHashMap<T, Boolean> internally rather than
Set<WeakReference<T>>. As it stands, null references will hang around forever.
I know it's just an illustration, but I bet lots of folks will copy it blindly.

  public aspect InstanceTracking<T> pertypewithin(org.xyz..*) {

      private Map<T, Boolean> instances = new WeakHashMap<T, Boolean>();

      after() returning(T t) : execution(new(..)) {
          instances.put(t, true);
      }

      public Set<T> getInstances() {
          return instances.keySet();
      }
  }

--tim



Back to the top