I\'m fairly new to Java (been writing other stuff for many years) and unless I\'m missing something (and I\'m happy to be wrong here) the following is a fatal flaw...
<The problem is you are instantiating a Java reference type. Then you pass that reference type to a static method, and reassign it to a locally scoped variable.
It has nothing to do with immutability. Exactly the same thing would have happened for a mutable reference type.
Are you sure it prints null? I think it will be just blank as when you initialized the foo variable you provided empty String.
The assigning of foo in thisDoesntWork method is not changing the reference of the foo variable defined in class so the foo in System.out.println(foo) will still point to the old empty string object.
Go do the really big tutorial on suns website.
You seem not to understand the difference scopes variables can be. "foo" is local to your method. Nothing outside of that method can change what "foo" points too. The "foo" being referred to your method is a completely different field - its a static field on your enclosing class.
Scoping is especially important as you dont want everything to be visible to everything else in your system.