【发布时间】:2018-05-03 08:15:21
【问题描述】:
这里是EventListener接口
package com.google.cloud.firestore;
public interface EventListener <T> {
void onEvent(@javax.annotation.Nullable T t, @javax.annotation.Nullable com.google.cloud.firestore.FirestoreException e);
}
这是Java部分代码 (参考https://firebase.google.com/docs/firestore/query-data/listen)
DocumentReference docRef = db.collection("cities").document("SF");
docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot snapshot,
@Nullable FirestoreException e) {
if (e != null) {
System.err.println("Listen failed: " + e);
return;
}
if (snapshot != null && snapshot.exists()) {
System.out.println("Current data: " + snapshot.getData());
} else {
System.out.print("Current data: null");
}
}
});
这是我转换成 Clojure 的代码
(defn outlook-synced-listenning
[^DocumentReference ref]
(let []
(-> ref
(.addSnapshotListener
(reify EventListener
(^void onEvent [this ^DocumentSnapshot snapshot ^FirestoreException e]
(if-not (nil? e)
(println " Listen failed: " + e)
)
(if (and (not (nil? snapshot)) (.exists snapshot))
(println " Current data: " + (.getData snapshot))
(println " Current data null ")
)
)))
)
))
这是错误
Caused by: java.lang.IllegalArgumentException: Can't find matching method: onEvent, leave off hints for auto match.
at clojure.lang.Compiler$NewInstanceMethod.parse(Compiler.java:8305)
at clojure.lang.Compiler$NewInstanceExpr.build(Compiler.java:7853)
at clojure.lang.Compiler$NewInstanceExpr$ReifyParser.parse(Compiler.java:7754)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6919)
我认为Clojure代码与Java接口不匹配时参数类型和类型提示的错误。
我想我仍然没有正确地将下面的代码行转换为 Clojure docRef.addSnapshotListener(new EventListener ()
请告诉我该怎么做。谢谢
【问题讨论】:
标签: clojure google-cloud-firestore