xml-xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Waite <m...@akuma.org>
Subject Re: No Collections API use?
Date Fri, 13 Aug 2004 04:46:33 GMT

On Aug 12, 2004, at 8:18 AM, David Smiley wrote:

> I read that document but JDK 1.5 support really is unrelated to what 
> I'm talking about.  The more I think about it, Collections API use is 
> clearly the right choice.  I don't buy the speed trade-off argument 
> Radu makes either.  We're not talking about low-level parsing or 
> graphics manipulation code; we're talking about high-level programming 
> abstractions.  If after this, one /still/ thinks we should use arrays, 
> then I ask to those people, when *does* one use Collections?

Actually, the speed trade-off was mine. This is due to arrays being a 
'quasi-native' type in java, vs. collections which are just objects 
with references to one another forming a data structure.

Really though, Collections are used for manipulation, correlation, and 
indexing of data; arrays do not handle any of these well. On the other 
hand, collections in java (< 1.5) have a major flaw, in that they leave 
the contained data completely untyped.

For example: given the following

...
<xs:ComplexType name='FooType'>
	<xs:Sequence>
		<xs:Element name='Name' type='xs:string'/ maxOccurs='unbounded'>
	</xs:Sequence>
</xs:ComplexType>
...

You can say right now my FooType object has a getNameArray() method 
which returns a String[]. You could change it to instead return an 
Iterator implementation, then write code like the following

Iterator it = foo.getNameIterator();
while (it.hasNext())
{
	String name = (String) it.next();
	...
}

Unfortunately, when someone on the project changes the schema file so 
that Name is now of BarType, your code will successfully compile, and 
everything may look fine until you see a ClassCastException during your 
regression testing.

-David Waite
Mime
View raw message