eclipse / eclipse-collections

Eclipse Collections is a collections framework for Java with optimized data structures and a rich, functional and fluent API.

Home Page:http://www.eclipse.org/collections

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Both api.factory.Lists and impl.factory.Lists are documented as "preferred way to create ..."

Bananeweizen opened this issue · comments

I'm slightly confused by both the api and impl factories being documented as preferred way to create new collections.

Background: I was going to set up preferred imports to simplify code completion in Eclipse. Personally I tend to add only the impl variant to the favorites, because it contains the adapt() method needed to work with Java Collections and will therefore lead to a good code completion in all cases. For reference, this is the related preference page in Eclipse:
image

Now I'm wondering if there are any architectural or other concerns to recommend either the api or impl Lists/Sets/... classes in code completion. Any thoughts and insights from the maintainers?

I would recommend using the impl factory classes in most cases. The api version goes through JDK ServiceLoader to find the appropriate factory class. The impl version goes directly to the factory class.

The api versions were created so that Eclipse Collections can create instances of containers in default methods in interfaces, thus allowing developers more flexibility at reducing duplicate code in Eclipse Collections. This is done this way so that we do not create direct dependencies between our api and impl jars. The downside is that we have duplicate classes to do that.

Thanks for the great explanation.