Dynamic (i.e responding to methodNotFound) classes in Java

Alex Buckley alex.buckley at oracle.com
Mon Jun 17 17:39:30 UTC 2013


While dynamic typing and dynamic method invocation did not make it into 
the Java language in SE 7, the concept of signature polymorphic methods 
did [1]. This allows a plain old virtual method invocation in the Java 
language to effect invocation of a dynamically typed method, via the 
java.lang.invoke.MethodHandle API and an upgraded invokevirtual 
instruction [2].

Alex

[1] http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.3
[2] 
http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokevirtual

On 6/13/2013 9:16 PM, Behrang Saeedzadeh wrote:
> Thanks for the clarification John. I also believe this was inconsistent
> with Java's philosophy, but I was just wondering what happened to that
> stuff.
>
> Cheers,
> Behrang Saeedzadeh
> http://www.behrang.org
>
>
> On Fri, Jun 14, 2013 at 12:05 PM, John Rose <john.r.rose at oracle.com> wrote:
>
>> On Jun 13, 2013, at 6:26 PM, Behrang Saeedzadeh <behrangsa at gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> A couple of years ago I downloaded an experimental build of JDK with
>>> invokedynamic support and it contained a class (DynamicObject?) that any
>>> method could be invoked on its subclasses without any compile time
>> errors.
>>>
>>> Does this class still exist? I can't find it anymore in the API docs.
>>
>> No.  There were partial prototypes in this direction as part of JSR 292,
>> but they were abandoned in 2009.  Here is a proposal from that time frame:
>>    https://wiki.openjdk.java.net/display/mlvm/DynamicJava
>>
>> Nothing like this exists or was built in any usable way.
>>
>> Untyped or "duck typed" invocation of objects can be done easily enough
>> with third-party libraries, or with reflection, or using a dynamic language
>> like JavaScript or JRuby or ${your_favorite_jvm_language}.
>>
>> In my opinion, Java the language is unlikely to support such a thing in
>> the near future, since there are many reasonable alternatives.
>>
>> — John



More information about the discuss mailing list