2
\$\begingroup\$

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?

asked Mar 15, 2012 at 20:03
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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.

answered Mar 16, 2012 at 22:04
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.