我有以下java类。
public class Toto {
public void aMethod(A a) {
System.out.println("A " + a);
}
public void aMethod(B b) {
System.out.println("B " + b);
}
}
我想覆盖 aMethod(A a) 而不是 aMethod(B b)。我能做到的唯一方法是:
(ns titi
(:gen-class :extends Toto
:exposes-method {aMethod parentMethod}))
(defn- -aMethod [this x]
(if (= (type x) A)
(println "ok do something here")
(.parentMethod this x)))
有一个更好的方法吗?(我的意思是自己不检查 x 的类型)。