Method reference assignment compatibility
Mark Mahieu
mark at twistedbanana.demon.co.uk
Thu Jun 26 04:27:21 PDT 2008
Neal,
Given a method with the signature:
void subscribe(Topic topic, {Message=>void} processor)
I might want to pass myPriorityQueue#offer(Message) as the second
argument, but this isn't permitted since Queue<E>#offer(E) has a
boolean rather than void result type.
Obviously I can get around this using a closure literal {Message msg
=> myPriorityQueue.offer(msg);}, however given:
final class Processor {
// ...
void process(Message msg) {
//...
}
}
In Java 6, if I were to alter the process(Message) method to return a
value, such as a boolean indicating success or failure of the
operation, then I'd break binary compatibility but I think source
compatibility would be preserved.
Under BGGA, if I had used a method reference myProcessor#process
(Message) as the argument to the subscribe() method above, then this
API change will have broken source compatibility.
So my question is: would it be problematic to allow a method
reference with a non-void result type to be assignment compatible
with an interface or function type with a void result type (all other
conditions being satisfied)?
Regards,
Mark
More information about the closures-dev
mailing list