• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

wrapper class

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

Boolean b = Boolean.parseBoolean("true");
Boolean c = Boolean.valueOf("true");
Float f = Float.valueOf("1011",2);
Every wrapper has a public void toString(); method

How many compilable or true (in case of 4) statements do you see ?

answer:3
They have given description:
The first 2 are true. Via autoboxing 1) goes into the variable. The valueOf returns a Boolean object anyhow. A little trick to remember the return type is: if you hear the primitive in it (pareInt, pareShort, intValue, shortValue...) then it returns a primitive, else an Object.

There is no parsexx & valueOf methods for Boolean in the K & B book. I am not getting why first two are true. Can anyone explain?
 
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

Originally posted by dolly shah:
... There is no parsexx & valueOf methods for Boolean in the K & B book...


But these methods are in the API.
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then why it is not marked in book?
 
marc weber
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

Originally posted by dolly shah:
Then why it is not marked in book?


Note that the numeric parseXxx and valueOf methods are discussed on p. 231 as methods that might throw a NumberFormatException. This does not apply to Boolean's methods.

I see Boolean's valueOf method indicated in the table on page 233, but not parseXxx. I think it just got missed here.
 
please buy this thing and then I get a fat cut of the action:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic