Hacker News new | ask | show | jobs
by aboodman 5515 days ago
I am not super familiar with all the details of Java inner classes, but why can't you get most of the way there by doing something like:

  DB.open(new Runnable() {
    public void run() {
      // ... do stuff here ...
    }
  });
You can even design your resource layers such that they can only be used this way (or are easiest to use this way).

Basically, I'm just stealing the JavaScript-y way of doing this that uses closures:

  DB.open(function() {
    ...
  });
1 comments

Answer: the inner class can only access constant locals :(. So you have to put any mutable state in members.

Blech. This might work for some cases, but would be a huge pain in the ass in others.