"-" <no****@hoem.com> wrote in message
news:42********@news.starhub.net.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 theJMenuThatIWantToSave = createSomeJMenuObject();
someInstanceOfJMenuBar.add(theJMenuThatIWantToSave );
.... versus ...
JMenu theJMenuThatIWantToSave =
someInstanceOfJMenuBar.add(createSomeJMenuObject() );
- Oliver