Skip to content

String[]::new treated as a complex argument, breaking member chains #1113

Closed

Description

@2is10

Prettier-Java 2.11.0

Input:

class A {

  void f() {
    var items = new ArrayList<>();
    items.stream().map(Object::toString).toArray(String[]::new);
    items.stream().map(Object::toString).collect(toCollection(ArrayList::new));
  }
}

Output:

class A {

  void f() {
    var items = new ArrayList<>();
    items
      .stream()
      .map(Object::toString)
      .toArray(String[]::new);
    items.stream().map(Object::toString).collect(toCollection(ArrayList::new));
  }
}

Expected behavior: Unchanged.

An array constructor reference like String[]::new should be treated just like ArrayList::new. Both are just constructor references.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions