• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Slightly confused with object value = null.

 
David Ward
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again folks! Just a quick couple of questions this time.

If I have initialized a load of Strings

I then change the string later if the conditions are true,


So, m9 becomes the module and room. However, later on m12 fails the IF and returns null instead. I kinda hoped that the first code where I initialized all the strings that I could force them to be "".

Anyway I can do an to cover all of my IF statements? Rather than one for each IF? Because I need to test for each hour period and day. Hope that makes sense. ;p
 
Harsha Smith
Ranch Hand
Posts: 287
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you haven't initialized all the strings except m17
 
David Ward
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I thought that but I'm sure I saw my tutor use something similar? shorthand to initialize them all?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the shorthand to avoid specifying each variable as a static String, but you still need to give them separate initial values (unless you're happy with the default).
 
David Ward
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys! Feel a bit foolish now! lol!

But of curiosity , if i were to keep each String as null until it passes the IF test, would I be able to catch all nulls and return ""?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can initialise all your strings like this

or you could use an array of strings
 
Harsha Smith
Ranch Hand
Posts: 287
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even better :-p
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And with lists?

 
David Ward
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much guys! Great info!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic