Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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