Skip to Main Content

Used to compile in java 7, not so much in java 8.

user10050369Jun 19 2015 — edited Jun 21 2015

The fails() method used to compile properly, but it doesn't anymore. The now() method seems to lose track of its return type and now forces me to cast (which I didn't have to do in java 7).  The problem seems to arise only if I use the new SelfLink(); using similarly typed interfaces works fine.


I may be doing something wrong, but for the life of me, I can't figure it out.


Here is the code.


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();
  
}

}

Comments
Post Details
Added on Jun 19 2015
3 comments
664 views