"-" <no****@hoem.co m> wrote in message
news:42******** @news.starhub.n et.sg...
there is a "public JMenu add(JMenu c)" method in JMenuBar.
i'm not good in programming and am wondering whether someone can provide
me with a clarification why Sun chooses to return a JMenu, rather than a
boolean or simply a void? returning a void won't be useful in determining
whether it is added hence that is understood.
in what scenario does returning the JMenu?
It's just a design decision. Returning a boolean for success or failure
is more of a C/C++ style of programming. In Java, it's typically better to
throw an exception if a failure occured.
As for why not returning void, if I designed the JMenuBar class, I'd
probably make it void. Still, I could see how it might be useful to have it
return the JMenu just added. Compare the following too pieces of code:
JMenu theJMenuThatIWa ntToSave = createSomeJMenu Object();
someInstanceOfJ MenuBar.add(the JMenuThatIWantT oSave);
.... versus ...
JMenu theJMenuThatIWa ntToSave =
someInstanceOfJ MenuBar.add(cre ateSomeJMenuObj ect());
- Oliver