【发布时间】:2014-08-16 07:34:13
【问题描述】:
我有以下 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 的类型)。
【问题讨论】:
标签: clojure clojure-java-interop