【发布时间】:2013-01-28 18:04:17
【问题描述】:
我找到了this related question on Stack Overflow,但它并没有真正回答我的问题。
我有一个已打包为 JAR 文件的 Java 应用程序。我还有一个已打包为 JAR 文件的 Clojure 应用程序。我现在正在编写另一个 Clojure 应用程序,它使用前两个作为库。
这似乎是我的错误来源的 Java 代码:
public class ServerBuilder {
private HashMap<String, ResponseObject> routes = new HashMap<String, ResponseObject>();
public int limit;
public ServerSocket serverSocket;
private ThreadBuilder threadBuilder;
public int count;
public ServerBuilder(int limit) {
this.limit = limit;
}
public void begin() throws IOException {
if(getServerSocket() == null) {
this.serverSocket = new ServerSocket(4444);
}
int count = 0;
while(count < limit) {
createThreadBuilder(serverSocket);
new Thread(threadBuilder).start();
count = count + 1;
this.count = count;
}
}
然后在我的 Clojure 代码中,我将像这样访问我的 Java 代码:
(ns browser_tic_tac_toe.core
(:import (server ServerBuilder)))
(defn -main []
(let [server-builder (ServerBuilder. 100)] ; the error points me to this line
(doto
server-builder (.begin))))
我得到的错误是:
Exception in thread "main" java.lang.IllegalArgumentException: No matching ctor found for class server.ServerBuilder
我已经用 Google 搜索过,但没有找到太多。该错误显然意味着“没有为此类找到匹配的构造函数”,但在我看来,构造函数确实匹配。这就是为什么我很困惑。
编辑
我尝试更改我传递的类型(从 long 到 int):
(defn -main []
(let [limit (int 100)
server-builder (ServerBuilder. limit)]
(doto
server-builder (.begin))))
【问题讨论】:
标签: java constructor clojure