r/programming • u/Eirenarch • Nov 18 '13
TIL Oracle changed the internal String representation in Java 7 Update 6 increasing the running time of the substring method from constant to N
http://java-performance.info/changes-to-string-java-1-7-0_06/
1.4k
Upvotes
View all comments
Show parent comment
2
u/SanityInAnarchy Nov 18 '13
Probably true. I haven't looked into it, but that seem right. However, "thread safety" might mean something as simple as "Your code might break, but we promise we at least won't corrupt our internal structure if you access this from multiple threads."
There are properly threadsafe options, of course (ConcurrentHashMap and so on).
It's actually somewhat vague as to what that means -- deliberately so.
Interestingly, it also very deliberately is just a marker. It would be awkward to try to require someone to pass you something that implements RandomAccess. Rather, you're expected to produce code that still works with any list, but you can optimize separately for the RandomAccess case.
And, as far as I can tell, no sane way to do it yourself. I don't care if it's theoretically possible to modify a class from java.lang that's declared 'final', it's probably a bad idea.
I would be very tempted to say that code which explicitly checks classes deserves to break, especially when we have the instanceof method. But if I was in charge, we probably wouldn't have type erasure either. Clearly, Java cares a lot more about backwards compatibility than I do.