<div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div>
<div class="protonmail_signature_block protonmail_signature_block-empty" style="font-family: Arial, sans-serif; font-size: 14px;">
    <div class="protonmail_signature_block-user protonmail_signature_block-empty">
        
            </div>
    
            <div class="protonmail_signature_block-proton protonmail_signature_block-empty">
        
            </div>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;">An improved method for expressing the self-type would certainly help, I think. Though I can see it failing with inheritance in generics:</div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;">```</div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">record Box<T>(T value) {}</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">class A {</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">  Box<this.class> boxed() {</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">    return new Box<>(this);</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">  }</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">}</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">class B extends A {}</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">B b = new B();</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">A upcast = b;</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">Box<A> boxA = upcast.boxed();</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span style="font-family: Menlo, Consolas, "Courier New", monospace;">Box<B> boxB = b.boxed();</span></div><div style="font-family: Arial, sans-serif; font-size: 14px;">```</div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><code>Box<A></code>​ and <code>Box<B></code>​ are incompatible types. So even though <code>boxA</code>​ and <code>boxB</code>​ are equivalent objects, we cannot assign <code>boxA = boxB</code>​ or have a method that accepts <code>Box<A></code>​ also accept <code>Box<B></code>​. Wildcards could help, except if your target demographic has little-to-no experience with generics.</div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;">Anyway. There's still the core issue that I'm trying to solve, which is giving meaningful names to complex generic types. Subclassing helps (and a "this" type would make it much better), but it still runs into issues where part of a library would want to use the base type and user code wants to use a subclass with a name meaningful to them (eg users wanting <code>Velocity</code>​ and library code wanting generic <code>Quotient<A, B></code>​ which may or may not fit the <code>Velocity</code>​ type contract). I'm having a hard time seeing any solution other than allowing types to be aliased - there'd be no potential for incompatible inherited types there's <i>no inheritance at all</i>.<br><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><div>- Sam</div></div><div class="protonmail_quote">
        On Monday, June 10th, 2024 at 7:00 PM, Archie Cobbs <archie.cobbs@gmail.com> wrote:<br>
        <blockquote class="protonmail_quote" type="cite">
            <div dir="ltr"><div dir="ltr">On Mon, Jun 10, 2024 at 5:01 PM Olexandr Rotan <<a target="_blank" href="mailto:rotanolexandr842@gmail.com" rel="noreferrer nofollow noopener">rotanolexandr842@gmail.com</a>> wrote:</div><div class="gmail_quote"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="auto">Also, I am not sure that complexity of this approach really justified by solved problem.</div></blockquote><div><br></div><div>I agree, it's just a thought. The self-type hierarchy spam problem also creates a high level of pain/complexity though.<br></div><div><br></div><div>I feel bad now for hijacking Sam's original email so I'll end my digression...<br></div><div><br></div><div>-Archie<br></div></div><br><span class="gmail_signature_prefix">-- </span><br><div class="gmail_signature" dir="ltr">Archie L. Cobbs<br></div></div>

        </blockquote><br>
    </div>