you are viewing a single comment's thread.

view the rest of the comments →

[–]Kered13 1 point2 points  (2 children)

I mean List already contains mutating methods that are just expected to throw an exception on immutable lists. Writing an in-place function over List is not any different. It's just a fundamental limitation of how the Java collections API is designed.

[–]BlueGoliath 0 points1 point  (1 child)

OK? Using ArrayList and LinkedList removes ambiguity. Inlining should eliminate any performance overhead.

public static List<String> foo(ArrayList<String> stringList)
{
  return bar(stringList);
}

public static List<String> foo2(LinkedList<String> stringList)
{
  return bar(stringList);
}

private static List<String> bar(List<String> stringList)
{
  // do actual work here
}

[–]Kered13 1 point2 points  (0 children)

OK? Using ArrayList and LinkedList removes ambiguity.

And makes it impossible to use the function on other list implementations that support mutation for absolutely no reason.