In the Eclipse APIs, the return and argument types are mostly arrays instead of collections. An example is the members
method on IContainer
, which returns IResources[]
.
I am interested in why this is the case. Maybe it is one of the following:
IResource[]
was better than just Collection
or List
ArrayList
internally holds an array which has more space than is needed (to offer an efficient implementation of add
), whereas an array is always constructed for just the needed target sizenull
)Does anyone have any insights or other ideas why the API was developed that way?
Posting this as an answer, so it can be accepted.
Eclipse predates generics and they are really serious about API stability. Also, at the low level of SWT passing arrays seems to be used to reflect the operating system APIs that are being wrapped. Once you have a bunch of tooling using Arrays I guess it makes sense to keep things consistent. Also note that arrays aren't subject to all of the type erasure issues when using reflection.
Yeah, I hear you as far as the collections api being generally much easier to work with for dynamic lists of items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With