if I have something like this
Map<String, Foo> foos;
...
Foo f = foos.get("key1");
foos.removeAll();
Am I still able to do String s = f.getSomeProperty();
if I have something like this
Map<String, Foo> foos;
...
Foo f = foos.get("key1");
foos.removeAll();
Am I still able to do String s = f.getSomeProperty();
Yes, you are. You just cleared the map, but the local variable f still holds a valid reference to the Foo and you still can use it.
foos holds only references to objects, not full objects. If you get something from foos, you get reference to that object and you can modify it. If you remove all elements from foos, then it no longer holds any reference, and those objects can be garbage collected only if there is no other references to that objects.
Note that String (note the capital S) is the name of the Java class which represents character strings. But yes, yes you are.
The simple answer is yes. f contains a reference to the object that foos.Get("key1") returned (assuming it is non-null). When you remove all from foos, you're simply removing the references from the foos object - you are not actually destroying the data that foos used to contain.
Yes f is Foo object and if Foo have some property that is string use it
Code:
Map<String, Integer> mp = new HashMap<String, Integer>();
mp.put("key1", 48);
mp.put("key2", 50);
mp.put("key3", 52);
mp.put("key4", 54);
mp.put("key5", 56);
mp.put("key6", 58);
Integer mytemp = mp.get("key1");
mp.clear();
System.out.println(mytemp);
Out:
48
that see mytemp is your f that is full object not only pointer