anonymous « primitive « Java Data Type Q&A

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

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() {

2. What's a reasonable way to mutate a primitive variable from an anonymous Java class?

I would like to write the following code:

boolean found = false;
search(new SearchCallback() {
  @Override void onFound(Object o) { found = true; }
Obviously this is not allowed, since found needs to ...

3. (Final) primitive used inside anonymous block

Yes indeed you are. And the first time you call print, you create a Runnable object which contains the "i" from the first time. The second time you call print, you use that same Runnable object. It still contains the "i" from the first time. So it's what jtahlborn said. And that would be true if you were using Generics (the ...