Returning an anonymous class that uses a final primitive. How does it work?

Posted by Tim P on Stack Overflow See other posts from Stack Overflow or by Tim P
Published on 2010-04-23T14:23:42Z Indexed on 2010/04/23 14:33 UTC
Read the original article Hit count: 351

Hi, I was wondering if someone could explain how the following code works:

public interface Result {
  public int getCount();
  public List<Thing> getThings();
}


class SomeClass {
...
  public Result getThingResult() {
    final List<Thing> things = .. populated from something.

    final int count = 5;

    return new Result {
      @Override
      public int getCount() {
        return count;
      }

      @Override
      public List<Thing> getThings();
        return things;
      }
    }
  }
...
}

Where do the primitive int , List reference and List instance get stored in memory? It can't be on the stack.. so where? Is there a difference between how references and primitives are handled in this situation?

Thanks a bunch, Tim P.

© Stack Overflow or respective owner

Related posts about anonymous-class

Related posts about primitive