Extension methods

Neal Gafter neal at gafter.com
Fri Nov 20 22:01:08 PST 2009


So the change in type is visible to applications: If there is a checkcast to
some superinterface of ExtMap it fails, but then after a cast to ExtMap, it
succeeds?  That sounds dangerous.

On Fri, Nov 20, 2009 at 5:53 PM, Rémi Forax <forax at univ-mlv.fr> wrote:

>  Le 21/11/2009 02:31, Neal Gafter a écrit :
>
> On Fri, Nov 20, 2009 at 5:34 PM, Rémi Forax <forax at univ-mlv.fr> wrote:
>
>> There is already an existing mechanism to insert extension methods
>> at runtime: interface injection
>> (
>> http://openjdk.java.net/projects/mlvm/subprojects.html#InterfaceInjection
>> )
>>
>> This mechanism allow to add an interface + implementation to a class at
>> runtime.
>>
>> Written in Java, it will be something like that:
>> package java.util;
>> public extension interface ExtMap<K,V> extends Map<K,V> {
>>   public Map.entry getEntry(K key) {
>>     ...
>>   }
>> }
>>
>> package java.util;
>> public interface Map<K,V> extension ExtMap<K,V> {
>>   ...
>> }
>>
>
> When at runtime is the extension done?  When ExtMap is statically
> initialized?
>
>
> The extension is done for each implementation of Map the first time
> there is a checkcast (and reflection counterparts) from an implementation
> of Map to ExtMap.
> ExtMap is initialized when needed as usual.
>
> Rémi
>



More information about the coin-dev mailing list