<div dir="auto">Oops, sorry!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 24, 2023, 2:16 PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

  
  <div>
    <font size="4"><font face="monospace">Did you mean to reply
        off-list?</font></font><br>
    <br>
    <div>On 5/24/2023 3:11 PM, - wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="auto">
        <div><br>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Wed, May 24, 2023, 1:48
              PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com" target="_blank" rel="noreferrer">brian.goetz@oracle.com</a>>
              wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
              <br>
              On 5/24/2023 1:52 PM, - wrote:<br>
              > Hello, quick question:<br>
              > If there's a nullable reference field in a
              null-restricted non-atomic <br>
              > value class, is this possible:<br>
              <br>
              We don't null-restrict classes, we null-restrict
              variables.  So I think <br>
              the above pencils out to:<br>
              <br>
                   __non-atomic value class X {<br>
                       public String? s;<br>
              <br>
                       public implicit X();<br>
                       public X(String! s) { this.s = s; }<br>
                   }<br>
              <br>
                   X! x;<br>
              <br>
              right?<br>
            </blockquote>
          </div>
        </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Yes. The field will be a reference than inlined
          as values. The constructor can be null-friendly in my question
          as well.</div>
        <div dir="auto">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <br>
              > 1. Declare a reference field, like a String, without
              heap pollution <br>
              > concerns;<br>
              > 2. Limit the values of fields (of course, permit
              zero-default values) <br>
              > for all instances of this class, such as nonnegative
              long field, null <br>
              > or String reference containing no tabs, etc.<br>
              <br>
              If I understand your question, you want to impose
              representational <br>
              invariants, with the proviso that the zero-default
              representation is <br>
              always valid.  To do so, you can declare an implicit
              constructor (which <br>
              produces the zero-default value) and an explicit
              constructor which does <br>
              the plain vanilla argument validation / mapping to
              representation that <br>
              constructors always do.<br>
            </blockquote>
          </div>
        </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">That is exactly what I am looking for. Great!</div>
        <div dir="auto">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <br>
              > This requires constructors to be executed for
              non-default instance <br>
              > creation, but individual field validation is
              independent, and valid <br>
              > object state is still the cartesian product of valid
              individual field <br>
              > states.<br>
              <br>
              The role of a constructor is to establish an object's
              state consistent <br>
              with its invariants.  But some invariants are per-field,
              and some are <br>
              cross-field:<br>
              <br>
                   class NonNegativeInt {<br>
                       // per-field invariants<br>
                       NonNegativeInt(int i) {<br>
                           if (i < 0) throw ...<br>
                           this.i = i;<br>
                       }<br>
                   }<br>
              <br>
                   class Range {<br>
                       // cross-field invariant<br>
                       Range(int lo, int hi) {<br>
                            if (lo > hi) throw ...<br>
                            ...<br>
                       }<br>
                   }<br>
              <br>
              The choice to accept non-atomicity should include "no
              cross-field <br>
              invariants", since a non-atomic value could tear under
              race.  Plenty of <br>
              classes, though, are more like NonNegativeInt than Range.<br>
              <br>
              Does this answer your question?<br>
            </blockquote>
          </div>
        </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Yes. Thank you so much, I indeed just need
          per-field invariants to hold true. The ability to have
          per-field invariants and nullable object reference fields in
          these classes also makes me think the current name,
          null-restricted (non-atomic) value classes is indeed a better
          name than primitive classes, which suggests behaviors in
          contrary to the two you've confirmed here.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Chen Liang</div>
        <div dir="auto">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            </blockquote>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </div>

</blockquote></div>