java - Values getting modified in the class during the runtime -
i trying loop around value got populated in registration class. have put breakpoint in getinstance()
method in registration class. when cursor reaches below loop code.
for (final registration.holderentry entry : registration.getinstance()) { // other things.. }
i f5 on that. , gooes getinstance()
method of registration class (below class). , when inspect on instance
variable @ point, see values populated in listofbundles
list good.
but if keep on pressing f5 again, @ point comes iterator
method in registration class , if inspect on listofbundles list
, don't see values in list not able understand why happening this. no other code running might change value of listofbundles
.
public class registration implements iterable<registration.holderentry> { private list<string> listofbundles = new linkedlist<string>(); private final map<string, holderentry> bundlemapper = new hashmap<string, holderentry>(); private registration() { // } private static class bundlesholder { static final registration instance = new registration(); } public static registration getinstance() { return bundlesholder.instance; } public synchronized void registerbundles(final string bundlename, final ibundlecollection collection) { holderentry bundleholder = new holderentry(bundlename, collection); bundlemapper.put(bundlename, bundleholder); listofbundles.add(bundlename); } @override public synchronized iterator<holderentry> iterator() { list<string> lst = new linkedlist<string>(listofbundles); list<holderentry> list = new linkedlist<holderentry>(); (string clname : lst) { if (bundlemapper.containskey(clname)) { list.add(bundlemapper.get(clname)); } } collections.reverse(list); return list.iterator(); } // other code }
i hope question clear enough. can tell me wrong going here?
because use static instance return same object from
public static registration getinstance()
method. (only 1 time registration initialize).
there no different object iteration. same object iterating on iteration. not applying every object changes make while iterate same object iterate , change values.
i dont know real requirement. try use this.
public static registration getinstance() { return new registration();; }
Comments
Post a Comment