I'm having an unexpected error while compiling this example code (in the fails() method). IntelliJ used to not report the error in the IDE, but it has since started to report it (some of the classes were in a library, which seemed to confuse it)
public class Main {
// The command
public interface ToMessageOperation<MODEL, MESSAGE> {
void run(MODEL object, MESSAGE message) throws Exception;
}
// A command
public class SelfLink<MODEL> implements ToMessageOperation<MODEL, LinkedMessage> {
@Override
public void run(MODEL object, LinkedMessage linkedMessage) throws Exception {
}
}
// A message type
public interface LinkedMessage {
void linkme();
}
// A message
public interface BootInfo extends LinkedMessage {
}
//The Executor
public interface GetRequest<MODEL, MESSAGE> {
GetRequest<MODEL, MESSAGE> runAll(ToMessageOperation<? super MODEL, ? super MESSAGE>... operations);
GetRequest<MODEL, MESSAGE> cleanUp();
MESSAGE now();
}
// The command factory
public SelfLink selfLink() {
return null;
}
public <MODEL, MESSAGE> GetRequest<MODEL,MESSAGE> get(Class<MESSAGE> message) {
return null;
}
public BootInfo works() {
return get(BootInfo.class).cleanUp().now();
}
public BootInfo alsoWorks() {
return get(BootInfo.class).runAll(new ToMessageOperation<Object, BootInfo>() {
@Override
public void run(Object object, BootInfo bootInfo) throws Exception {
}
}).now();
}
public BootInfo surprisedItWorks() {
return get(BootInfo.class).runAll(new ToMessageOperation<Object, LinkedMessage>() {
@Override
public void run(Object object, LinkedMessage message) throws Exception {
}
}).now();
}
public BootInfo fails() {
return get(BootInfo.class).runAll(new SelfLink()).now();
}
}
I'm a bit surprised that the error only happens when I add the runAll() method, as all methods return the same objects.
I'm really surprised that the method works with different types that are assignable from the failing case ( where the ToMessageOperation type is inherited instead of being explicit ). And even that shouldn't change the return type, right ?
Am I doing something wrong ?