I wrote a non-blocking MySQL interface for java (wrapped around the standard mysql java connector).

I think the code to use it looks a bit ugly however...

db.rawQuery(queries.someAlreadyPreparedStatement, (new Callback(){
    public void result(ResultSet result){
        while (result.next()) {
            //Handle each row from the result and do any processing

How could this be improved? Is this as good as it gets?


1 Answer 1


This is as good as it gets in Java. The idea of callbacks are very popular, and are the foundation of functional languages. Even Javascript offers a cleaner approach, as JQuery shows. Unfortunately for Java, anonymous inner classes (as you have) are the shortest way to create a function like this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.