• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Boolean.valueOf(boolean) vs Boolean.valueOf(String)

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the Boolean javadoc:



Wheras:




What I am not able to understand is that since for both methods return type is same, how come for one a new Boolean instance is being returned and for the other boolean primitive is being returned.

Any pointers will help.

Thanks
Abhishek
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes you think a boolean primitive is being returned by either of them, since the Javadocs say that both return a Boolean object?
 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Detailed from the javadoc:



Returns a Boolean instance representing the specified boolean value. If the specified boolean value is true, this method returns Boolean.TRUE; if it is false, this method returns Boolean.FALSE.

Parameters:
b - a boolean value.
Returns:
a Boolean instance representing b.


Returns a Boolean with a value represented by the specified String. The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
Example: Boolean.valueOf("True") returns true.
Example: Boolean.valueOf("yes") returns false.

Parameters:
s - a string.
Returns:
the Boolean value represented by the string.

And since the second method does not return an instance, it is recommended to be used instead of constructor Boolean(String value).

 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhishek Asthana wrote:Detailed from the javadoc:



Agreed with Matthew. And I am not sure how this detail from javadoc is to be used to confirm the original question. The JavaDoc clearly states that both methods return a Boolean instance, and not a primative.

[EDIT] Oh I see now. In the example of the Javadoc (and not in the latest java 6 doc), the author mistakenly used lower case. Regardless, if you look at the signature of the method, two lines up, it is obvious that it is a documentation error.... And BTW, it looks like the java 6 javadoc remove those statements entirely.


Henry
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic