<div dir="ltr">I am reading Weld code to understand deeply how proxies work.<div><br></div><div>While doing this, I ran across the <font face="monospace">Proxies.TypeInfo</font> class.  It has a method called <font face="monospace">getSuperInterface()</font>.</div><div><br></div><div>This method iterates over a set of interfaces and selects the most specific one (somewhat surprisingly to me; I would have expected the most general one).</div><div><br></div><div>The method is very short so here it is in its entirety, reformatted:</div><div><font face="monospace"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace">public Class&lt;?&gt; getSuperInterface() {</font></div><div><font face="monospace">  if (interfaces.isEmpty()) {</font></div><div><font face="monospace">    return null;</font></div><div><font face="monospace">  }</font></div><div><font face="monospace">  Iterator&lt;Class&lt;?&gt;&gt; it = interfaces.iterator();</font></div><div><font face="monospace">  Class&lt;?&gt; superclass = it.next();</font></div><div><font face="monospace">  while (it.hasNext()) {</font></div><div><font face="monospace">    Class&lt;?&gt; clazz = it.next();</font></div><div><font face="monospace">    if (superclass.isAssignableFrom(clazz)) { // XXX Is this backwards?</font></div><div><font face="monospace">      superclass = clazz;</font></div><div><font face="monospace">    }</font></div><div><font face="monospace">  }</font></div><div><font face="monospace">  return superclass;</font></div><div><font face="monospace">}</font></div></blockquote><div><br></div><div>For example, if there are exactly two interfaces in the set, <font face="monospace">Square.class</font> and <font face="monospace">Rectangle.class</font>, and <font face="monospace">Square extends Rectangle</font>, it would seem that <font face="monospace">Square.class</font> will be selected.</div><div><br></div><div>(My reading: Pretend <font face="monospace">Square.class</font> is the first item in the iterator.  It gets assigned to <font face="monospace">superclass</font>.  Then <font face="monospace">clazz</font> gets the next (and last) item, <font face="monospace">Rectangle.class</font>.  Then we check to see if (effectively) <font face="monospace">Square.class.isAssignableFrom(Rectangle.class)</font>, which will return <font face="monospace">false</font>.  So <font face="monospace">superclass</font> remains <font face="monospace">Square.class</font> and is returned.</div><div><br></div><div>(Or pretend that <font face="monospace">Rectangle.class</font> was the first item in the iterator.  It gets assigned to <font face="monospace">superclass</font>.  Then <font face="monospace">clazz</font> gets <font face="monospace">Square.class</font>.  Then we check to see if <font face="monospace">Rectangle.class.isAssignableFrom(Square.class)</font>, which returns <font face="monospace">true</font>, so <font face="monospace">superclass</font> gets reassigned to <font face="monospace">Square.class</font>, and is then returned.  Hence <font face="monospace">Square.class</font>, the most <i>specific</i> subtype in the set, is returned in both cases.)</div><div><br></div><div>The reason this surprised me is the name of this method implies that it should select the most <i>general</i>, e.g. <font face="monospace">Rectangle.class</font> in my example.  That&#39;s usually what &quot;super&quot; means.</div><div><br></div><div>See <a href="https://github.com/weld/core/blob/10a1d11af8c815a2a4a8fc5a4061698215e602b0/impl/src/main/java/org/jboss/weld/util/Proxies.java#L86">https://github.com/weld/core/blob/10a1d11af8c815a2a4a8fc5a4061698215e602b0/impl/src/main/java/org/jboss/weld/util/Proxies.java#L86</a>.</div><div><br></div><div>Is that line &quot;backwards&quot;?  Or is it just a badly-named method (should it have been named <font face="monospace">getMostSpecificInterface()</font>)?  Or…?</div><div><br></div><div>I understand this code is old and works and so my apologies if I&#39;m being stupid in some way.  I just like to understand things.</div><div><br></div><div>Best,</div><div>Laird</div></div>