• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

String values

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

are the following 3 valid uses of string ?

String s ="i'm a string";
String s = (String) 'i'm a string';
String s = null;

cheers

chris
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String s = "i'm a string"; -- valid
String s = (String) 'i'm a string'; -- not valid , invalid char, no ''
String s = null; -- valid, can always set an object to null


cheers Rille
 
Chris Davies
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String s = "i'm a string"; -- valid
String s = (String) 'i'm a string'; -- not valid , invalid char, no ''
String s = null; -- valid, can always set an object to null


so you can't expicitly cast an object to a value ? is it because string is not a wrapper class ?

cheers

chris
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chris,

Did you try to compile your code snippet? A few compiler errors are worth a thousand words of explanation in a forum; OK, maybe only a hundred.

In any case, your example 2 uses single quotes.

Let me ask you (pull out your compiler please) is this one valid?

String s = (String) "i'm a string";
 
Chris Davies
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i see it. its what i originally thought but number 2 threw me a bit in terms of casting.

cheers

chris
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic