1

is it possible to proxy a class like this and override both methods?

public abstract class C {
  ...
  public abstract void m(String a);
  public void m(Integer a) {}
}

this doesn't work:

(proxy [C] []
  (m [^String a])
  (m [^Integer a]))

;; java.lang.IllegalArgumentException: Method 'm' redefined

my current workaround is to write a proxy-friendly java class that renames the overload:

public abstract class C2 extends C {
  @Override
  public void m(Integer a) { this.m2(a); }
  public abstract void m2(Integer a);
}

but would be nice to have a solution that doesn't require javac in the build

0

1 Answer 1

3

Include one method m in your proxy. Do not type-hint the parameter. Let the function check the actual parameter type at run-time and behave accordingly.

(If the methods in question differed in arity, you would need to declare the proxy method argument list as [ & x], i.e., receiving all parameters, however many they might be, as a vector. This technique helps when you want to proxy java.io.Writer for example.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.