3 ms·
I was trying to reduce the amount of concepts I had to invoke to make the example make sense. java.lang.String is a final class so in this case so doSomething
by marginalia_nu 3y ago
I was trying to reduce the amount of concepts I had to invoke to make the example make sense.
java.lang.String is a final class so in this case so doSomething can't be overridden, and strong assumptions can be made about doSomething's behavior and in practice it's likely inlined given that this is an extremely hot method.
Since this is a constructor, the reference can't be aliased by e.g. fields in the class, so static analysis of the code is surprisingly easy. The compiler just needs to answer whether this particular reference is mutated by the invoked function(s).
- haspok 3y agoOK, this makes sense, thanks.