Given an interface
public interface Foo {
void bar(Object o);
}
And a proxy over that interface:
(proxy [Foo] []
(bar [o] (baz o)))
When the interface gets updated to
public interface Foo {
void bar(Object o);
// java 8 default method, quote from
// https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html
// "Default methods enable you to add new functionality to the
// interfaces of your libraries and ensure binary compatibility
// with code written for older versions of those interfaces."
default void bar(Object o, Object p) {
bar(o);
}
}
Calls to instanceCreatedByProxy.bar(o, p)
will not work as it could be expected.
reify
is not affected by this.
Repro repo: https://github.com/imrekoszo/proxy-default
There is no indication of this behavior in the docstring of proxy
, the only reference I saw to this is an example on clojuredocs.
This is troublesome as it might prevent an otherwise non-breaking library upgrade. If the code calling proxy
is under one's control they could use reify
instead (especially as this is recommended in the official docs). However if it is in an external library this is not a viable workaround.
Is this a bug or a known limitation of proxy
?
If the latter, then could this perhaps be made more visible, for example through a warning in the docstring?
Edit:
- link to original slack thread
- added link to reify
recommendation