Is the formatting below some kind of convention in Java? I personally found it more difficult to read, than the second example. Am i alone here? And is there a way to make such a custom formatting in NetBeans when choosing Source -> Format?
public boolean handleEvent(Event e) {
if (e.target == quit) System.exit(0);
else if (e.target == parent) {
// Code here
// Bug workaround
}
catch (IOException ex) { infoarea.setText("I/O Error"); }
return true;
}
(second example)
public boolean handleEvent(Event e)
{
if (e.target == quit) System.exit(0);
else if (e.target == parent)
{
// Code here
// Bug workaround
}
catch (IOException ex) { infoarea.setText("I/O Error"); }
return true;
}
Although the given code doesn’t compile, I assume you are talking about using opening braces on the same line as the class/method/command, as opposed to taking a new line before using them?
If so, It’s really a totally subjective thing – I personally hate having my braces on a new line; it looks as wrong to me as same line ones do to you. The only important thing is to make sure that if you’re working in a team, you’re all sticking to the same conventions – there’s no real right/wrong for this matter.