Is there a way to auto-generate code when anonymously declare a new instance of abstract class, thanks in advance.
Here's is an example :
My abstract class :
public abstract class MySqlQueryHelperCallback {
/**
*
* @param rs ResultSet for precedent sql request
*/
protected void queryResult(ResultSet rs)
{
try
{
while (rs.next())
{
//Whatever
}
} catch (SQLException e)
{
e.printStackTrace();
}
};
}
What happens when i anonymously create an instance :
test.executeQuery("SELECT * FROM visiteur", new MySqlQueryHelperCallback() {
@Override
protected void queryResult(ResultSet rs)
{
super.queryResult(rs);
}
});
What i would like to happens :
test.executeQuery("SELECT * FROM visiteur", new MySqlQueryHelperCallback() {
@Override
protected void queryResult(ResultSet rs)
{
try
{
while (rs.next())
{
//Whatever
}
} catch (SQLException e)
{
e.printStackTrace();
}
};
});
The Java language does not support auto-generation.
Rather, auto-generation is / would be implemented by a tool such as your IDE. So what you should be doing is look at your IDE's mechanisms for auto-generating code. These will depend on what IDE you are using.
For example, in Eclipse, you can define custom code templates to do this kind of thing.