• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

booleanValue();

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


what is the result ?

Now the answer given is :-

E. The compiler fails at line 10 because b1 is a reference variable to a Boolean wrapper object, not a boolean primitive.[ which is absolutely Fine.]

My question is :- I thought line 5 [ aka b2 = b1.booleanValue(); ]
should have been the culprit, since there is nothing like a 'booleanValue'.
I ran the above code , and the compiler prooves me wrong( absolutely Fine here too )... but why ?
TIA
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could you please explain what you mean with "since there is nothing like a 'booleanValue'". I'm afraid I don't get that one

Line 5 is absolutely legal - you call the booleanValue() function on Boolean object (this function returns boolean primitive), and then you assign the return value to another boolean primitive b2.

You might want to look up the Boolean class in Java API Docs for more info on booleanValue() function.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Boolean (Class) Method Summary:

boolean booleanValue()
Returns the value of this Boolean object as a boolean primitive
 
Netty poestel
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whoa!
since I was on the wrapper chapter, seeing booleanValue() I assumed that this has to do with the xxxValue() conversion utility.
and in the Common Wrapper Conversion Methods the only methods available for this are "byteValue,doubleValue ,floatValue ,intValue ,longValue ,shortValue"

but it seems the reply given is again "news for me"
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that Byte, Short, Integer, Long, Float, and Double all extend Number, which contains the six numeric xxxValue() methods.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Number.html

Boolean and Character do not inherit from Number. So booleanValue() and charValue() are unique to their respective wrappers.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Netty poestel:
whoa!
since I was on the wrapper chapter, seeing booleanValue() I assumed that this has to do with the xxxValue() conversion utility.
and in the Common Wrapper Conversion Methods the only methods available for this are "byteValue,doubleValue ,floatValue ,intValue ,longValue ,shortValue"

but it seems the reply given is again "news for me"




Don't "assume" anything. When you are learning something new about Java read the Java API in conjunction with your book. And at least try to understand what the Java Language Specification says about it (for the basics).
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic