Skip to content

koresframework/KoresExperiments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KoresExperiments

Comic: This is an experiment project. Everything here is only made for fun and may explode if you put something wrong inside.

Dynamic dispatch

public class Person { 
    public String getName() { ... }
}

public class Cat { 
    public String getName() { ... }
}

public interface MyDispatcherInterface {
    String getName(Object o);
}

public class Main {
    public static void main(String[] args) {
        MyDispatcherInterface mdi = KoresExperimentsIndyHelper.create(MyDispatcherInterface.class, DynamicDispatch.EXPERIMENT);
        
        Person person = ...;
        Cat cat = ...;
        
        String personName = mdi.getName(person);
        String catName = mdi.getName(cat);
    }
}

Late binding

public class Main {
    public static void main(String[] args) {
        MyDispatcherInterface mdi = KoresExperimentsIndyHelper.create(MyDispatcherInterface.class, LateBinding.EXPERIMENT);
        
        Person person = ...;
        Cat cat = ...;
        
        String personName = mdi.getName(person); // Binded to 'Person' type, cannot invoke method of any other type anymore, but consecutive invocations are meant to be faster
        String catName = mdi.getName(cat); // ClassCastException
    }
}

Experiment annotation

@Experiment(DynamicDispatch.class)
public interface MyDispatcherInterface {
    @Dynamic // DynamicDispatch
    String getName(Object o);
}
public class Main {
    public static void main(String[] args) {
        MyDispatcherInterface mdi = KoresExperimentsIndyHelper.createFromInterface(MyDispatcherInterface.class);
        
        Person person = ...;
        Cat cat = ...;
        
        String personName = mdi.getName(person);
        String catName = mdi.getName(cat);
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages