R
Rhino
I am trying to subclass TreeSet to hold a Set of Strings. However, I'm
having some problems with the size() method.
Given this class definition:
public class StringSet extends TreeSet {
String[] sexes = new String[] {"M", "F"};
public StringSet(String[] values) {
stringSet = new TreeSet();
for (int ix=0; ix<values.length; ix++) {
stringSet.add(values[ix]);
}
System.out.println("StringSet(): The StringSet contains " +
stringSet.size() + " strings.");
}
}
and this code:
String[] sexes = new String[] {"M", "F"};
StringSet sexesSet = new StringSet(sexes);
System.out.println("setup(): sexesSet.size() = " + sexesSet.size());
I'm finding that the println() within the StringSet constructor correctly
reports that there are two elements in the StringSet but the println() that
follows the instantiation of the StringSet incorrectly reports a size of 0.
I can't see a mistake in my code but I'm doubtful that there would be a bug
in Java that causes the StringSet size to be misreported. Can anyone see
what is wrong here?
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
having some problems with the size() method.
Given this class definition:
public class StringSet extends TreeSet {
String[] sexes = new String[] {"M", "F"};
public StringSet(String[] values) {
stringSet = new TreeSet();
for (int ix=0; ix<values.length; ix++) {
stringSet.add(values[ix]);
}
System.out.println("StringSet(): The StringSet contains " +
stringSet.size() + " strings.");
}
}
and this code:
String[] sexes = new String[] {"M", "F"};
StringSet sexesSet = new StringSet(sexes);
System.out.println("setup(): sexesSet.size() = " + sexesSet.size());
I'm finding that the println() within the StringSet constructor correctly
reports that there are two elements in the StringSet but the println() that
follows the instantiation of the StringSet incorrectly reports a size of 0.
I can't see a mistake in my code but I'm doubtful that there would be a bug
in Java that causes the StringSet size to be misreported. Can anyone see
what is wrong here?
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare