3 ms·
The Typescript way would only work for local variables in Java. Since another thread might update a field between the instanceof check and the use of the field.
by papercrane 4y ago
The Typescript way would only work for local variables in Java. Since another thread might update a field between the instanceof check and the use of the field.
- SemanticStrengh 4y agothose cases are rare. Defensive copying should be optin, not the default. Java really deep copy objects for even the most basic instanceof checks??
- kaba0 4y agoYou can’t change the object’s type in Java, so if you hold on to the same reference it will be safe to use after the instanceof check.
- zarzavat 4y agoYou’re definitely holding it wrong if you have polymorphic fields in your lock-free shared memory. Or at least holding it weirdly.
- gizmo686 4y agoThats the problem with language design. If the language allows something, it needs to correctly support it; even if actually doing it is a bad idea.
- peterkelly 4y agoThis is an issue in TypeScript even with single-threaded code; it (always/sometimes?) assumes function calls won't affect the results of type narrowing tests: https://github.com/microsoft/TypeScript/issues/9998 https://github.com/microsoft/TypeScript/issues/9998