Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use a single Supplier instance inside a configured MultiMapBuilder #5676

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CodingFabian
Copy link

fixes #5673

@google-cla google-cla bot added the cla: yes label Aug 9, 2021
@CodingFabian
Copy link
Author

This change required a bit of generics magic, since previously the suppliers got a type assigned that was dependent on the V type of the assigned variable (from the return type of the build signature)

I followed the pattern already existing for EnumSet to derive V from V0, and that does compile correctly with the forced V0 -> V casts

generally speaking: the type here doesn't matter. the Suppliers will always create empty backing collections which can be of any type at compile time and runtime.

if there is a better way to do this, I appreciate the insight

@cgdecker cgdecker added the P3 label Aug 9, 2021
@cgdecker cgdecker requested a review from cpovirk August 9, 2021 14:37
@CodingFabian
Copy link
Author

If consistency is preferred, I think we can rework LinkedListSupplier supplier to also use an instance per builder, instead of the lazily initialized global one.

private enum LinkedListSupplier implements Supplier<List<?>> {
    INSTANCE;

    public static <V extends @Nullable Object> Supplier<List<V>> instance() {
      // Each call generates a fresh LinkedList, which can serve as a List<V> for any V.
      @SuppressWarnings({"rawtypes", "unchecked"})
      Supplier<List<V>> result = (Supplier) INSTANCE;
      return result;
    }

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MultimapBuilder creates unnecessary objects
2 participants