Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String values

 
Chris Davies
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • 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
 
Rikard Qvarforth
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic