This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
But....
Posted by Hiran on October 31, 2001 at 2:14 PM
> > - The second case sounds like what you want (sounds like you want an unitialized String), but you don't need to explicitly initialize it to null, since that is the default behavior.
>
There's a problem though. Here's my code: public String getNextLocName(String direction) { String nextLocName; for (int i=0; i { if (directions[i].equalsIgnoreCase(direction)) { nextLocName = assocLocs[i]; } } return nextLocName; } When I try to run it, an error comes up saying that nextLocName might not be initialized. So do I have to put String nextLocName = null;? (In case you're wondering, the method that calls this method takes the string that's returned and runs it through a for loop checking to see if nextLocName is equal to null or not). Hiran
Replies:
|