2 ms·
Can't understand why people in this thread seem so ticked about this. The author's observation is interesting and useful to know, but this is an edge case that
by bcg1 11y ago
Can't understand why people in this thread seem so ticked about this.
The author's observation is interesting and useful to know, but this is an edge case that is easily fixable and actually kind of the fault of user code, not the implementation or the spec.
Its not so simple to just say "I can't believe they changed the performance of xyz"... the author's article is about just one usage pattern, and there is no evidence presented to show it is very common compared to others. Developers needing specific behavior for this pattern could easily have used java.nio.CharBuffer which makes allocation/copying/access to the underlying array/etc explicit, and just happens to implement CharSequence. No reimplementation of String necessary.
In general, Java is not C or C++, and has never been billed as a platform where you could rely on the internal representation of anything unless it is specified as such. Even the same bytecode running on the same platform on the same machine can run differently if the hotspot compiler says Make It So. That of course assumes you are even using Oracle's JVM or OpenJDK... there are in fact other implementations of both the JVM and the standard library that are free to implement things however they want.
Even within the Oracle/OpenJDK sphere - there are 4 different garbage collectors which all could affect this pattern differently. There is even a new String dedup feature that would have an impact on the internal behavior of Strings:
https://blog.codecentric.de/en/2014/08/string-deduplication-new-feature-java-8-update-20-2/ https://blog.codecentric.de/en/2014/08/string-deduplication-...
tl;dr - don't assume and pick the right tool for the job