String.contains(CharSequence) calls toString on argument

Aleksey Shipilev aleksey.shipilev at oracle.com
Fri Mar 20 12:31:58 UTC 2015


On 03/20/2015 03:28 PM, Aleksey Shipilev wrote:
> I wonder if the change is "only" about specializing
> indexOf(CharSequence) on the Java side to shortcut to indexOf(String)
> and others, like String.contentEquals(CharSequence) already does.

Ah, sorry for the confusion, contains(CharSequence) already
"specializes" via shortcut in

  String toString() {
      return this;
  }

  public boolean contains(CharSequence s) {
     return indexOf(s.toString()) > -1;
  }

So the question is about StringBuffers/StringBuilders then?

-Aleksey.




More information about the core-libs-dev mailing list