Search code examples
javacollectionsjunit4

Where is toString() overridden on java.util.List


I was wondering why this assert works in JUnit:

assertEquals("[String1, String2, String3]", Arrays.asList("String1", "String2", "String3").toString());

I can't see the toString() being overridden anywhere on List or Collection.

I'm glad it works, but, still curious.


Solution

  • Arrays.asList returns an Arrays#ArrayList that extends AbstractList which extends AbstractCollection which implements toString.