Revisiting default values
daniel.smith at oracle.com
Wed Aug 5 22:54:46 UTC 2020
> On Aug 5, 2020, at 2:11 AM, Peter Levart <peter.levart at gmail.com> wrote:
> On 8/5/20 10:05 AM, Peter Levart wrote:
>> Javac could emit a check before accessing a field from code where embedded check is not performed (where instance is not "this") and before invoking default interface method (as determined by static type)
> ...hm, javac could not do that, right? It does not know if the instance is of inline class at that time and of which inline class. This is only possible during runtime...
> But at least for field accesses this could work.
Correct. In theory, for method invocations, javac could do something reflective for *every* invocation involving Object or an interface. Something like:
Runnable obj = ...;
if (obj.getClass().isInline() && obj.getClass().defaultValue() == obj)
throw new InvalidDefaultInstanceException();
But of course that's a huge burden on every Java program in the world, without regard to whether they expect to encounter Bucket #3 inline classes.
It's a similar story for Option H—compiler checks on array reads from Object, Runnable, etc.
More information about the valhalla-spec-observers