octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #51804] java-9: java.base/java.lang.Double can


From: Andrew Janke
Subject: [Octave-bug-tracker] [bug #51804] java-9: java.base/java.lang.Double cannot be cast to java.base/java.lang.Integer
Date: Thu, 19 Jul 2018 02:39:59 -0400 (EDT)
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36

Follow-up Comment #14, bug #51804 (project octave):

> It's not documented, I can only guess that the Comparable<T> interface also
defines a compareTo(Object) method that internally tries to cast the object to
type T.

Basically, yes: That "compareTo(Object)" method is a "bridge method"
implicitly synthesized by the Java compiler to support the "type erasure"
mechanism of Java generics. Internally, it'll do the cast and pass the call on
to the specialized "compareObject(Integer)" that the java.lang.Integer source
code actually defines. See
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ102
if you care about the details.

You can see the details using "javap" to disassemble the class files in the
JRE's `rt.jar` if you're curious. Here's what `compareTo(Object)` looks like
in JDK 8:


  public int compareTo(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #1                  // class java/lang/Integer
       5: invokevirtual #96                 // Method
compareTo:(Ljava/lang/Integer;)I
       8: ireturn


I don't think you can rely on the ordering of the Java methods coming back
from java.lang.Class's Reflection methods like getMethods() and
getDeclaredMethods(). That's implementation-dependent. And it looks like the
implementation-dependent ordering changed between JVM versions here. 

>From the documentation for java.lang.Class.getMethods 
<https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethods-->:

> The elements in the returned array are not sorted and are not in any
particular order.

You'll need to sort the methods by degree of specialization or matching to the
input types to determine what sort of conversion to do and which method to
call. Non-trivial.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51804>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]