By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

public JMenu add(JMenu c)

P: n/a
-
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?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"-" <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
Aug 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.