Extension methods
Rémi Forax
forax at univ-mlv.fr
Sat Nov 21 04:23:48 PST 2009
Le 21/11/2009 07:01, Neal Gafter a écrit :
> 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.
ExtMap is an extension interface not an interface.
I've reused the keyword extends here between an extension interface and
an interface,
It seems its not the best keyword to explain the relation between an
extension interface
and the interface it enhance.
Let use 'enhances' instead of extends.
package java.util;
public extension interface ExtMap<K,V> enhances Map<K,V> {
public Map.Entry getEntry(K key) {
...
}
}
I propose the following rules:
- an extension interface can enhance only one interface
(it's simpler at runtime).
- an extension interface can neither extends an interface nor extends
an extension interface.
(the later is because extension methods carry codes).
So ExtMap can't extends an interface.
Rémi
>
> On Fri, Nov 20, 2009 at 5:53 PM, Rémi Forax <forax at univ-mlv.fr
> <mailto: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
>> <mailto: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