On Thu, 10 Sep 2026 08:56:11 GMT, Serguei Spitsyn <[email protected]> wrote:

>>> 1. Null-restricted flat field without a null marker case:
>>> 
>>> ```
>>> value class Point { int x, y;}
>>> class XXX { Point! point; // null-free; eligible for flat storage without a 
>>> null marker
>>> }
>>> ```
>> 
>> I couldn't compile the code with following error. Can we use `!`? It does 
>> not seem to be mentioned in JEP 401.
>> 
>> 
>> $ LANG=C 
>> ~/github-forked/jdk/build/linux-x86_64-server-fastdebug/images/jdk/bin/javac 
>> --release 28 --enable-preview Test2.java
>> Test2.java:12: error: <identifier> expected
>>   Point! point;
>>        ^
>> Test2.java:12: error: <identifier> expected
>>   Point! point;
>>               ^
>> 2 errors
>
>> I couldn't compile the code with following error. Can we use !? It does not 
>> seem to be mentioned in JEP 401.
> 
> Sorry. I've never used it myself. It seems to be the old syntax. Try the 
> annotation `@NullRestricted` instead:
> 
> value class Point { int x, y;}
> class XXX {
>     @NullRestricted
>     Point point = new Point(1, 2);
> }

@sspitsyn @plummercj 
Thanks for your reivew!
I updated LingeredAppWithValueObject.java to test value objects in SA. It has 
following classes/fields. I think it can test value objects what @sspitsyn 
mentioned.


    public static value class ValueObj {

        public final byte a;
        public final Rec  rec;
        public final Rec  nullField;

        public ValueObj(byte a, byte recA, byte recB) {
            this.a = a;
            this.rec = new Rec(recA, recB);
            this.nullField = null;
        }
    }

    public static value class NonNullValueObj {

        public final byte a;
        public final Rec  rec;

        public NonNullValueObj(byte a, byte recA, byte recB) {
            this.a = a;
            this.rec = new Rec(recA, recB);
        }
    }

    public static value class NonFlattenedValueObj {

        public final int a;
        public final Object obj;

        public NonFlattenedValueObj(int a, Object obj) {
            this.a = a;
            this.obj = obj;
        }
    }

    private static ValueObj valObj;

    @NullRestricted
    private static NonNullValueObj nonNullValObj;

    private static NonFlattenedValueObj nonFlattenedValObj;

-------------

PR Comment: https://git.openjdk.org/jdk/pull/32310#issuecomment-5618027094

Reply via email to