Avoiding API Methods with Implicit Object Allocations
API methods returning (part of) the internal state of an object usually
- allocate a new object
- copy internal state of source object into new object, sometimes with conversion into different representation
Examples:
- ByteArrayOutputStream.toString()
- ByteArrayOutputStream.toByteArray()
Usually, programmer cannot override this time-consuming semantics even if copy of internal state is unnecessary
Slide 17