简体   繁体   English

将Czyjure中的LazySeq返回给Java时出现ClassCastException

[英]ClassCastException when returning LazySeq from Clojure to Java

I have Clojure function that returns a LazySeq. 我有Clojure函数返回一个LazySeq。 When I run this function from the REPL, it works just fine. 当我从REPL运行此函数时,它工作得很好。 However, if I try to call the same function from Java code like this: 但是,如果我尝试从Java代码调用相同的函数,如下所示:

Object result = com.acme.forecast.core.runforecast("file1.csv", "file2.txt");

I get the following exception: 我得到以下异常:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: 
  clojure.lang.LazySeq cannot be cast to java.lang.Number
    at com.acme.forecast.core.runforecast(Unknown Source)
    at com.acme.forecast.client.gui.ClientGUI.actionPerformed(ClientGUI.java:180)

My gen-class says I'm returning a LazySeq, not a Number: 我的gen-class说我正在返回一个LazySeq,而不是一个数字:

  (:gen-class
    :name com.acme.forecast.core
    :methods [#^{:static true} [runforecast [String String] clojure.lang.LazySeq]])

What is going wrong here? 这里出了什么问题?

The error does say you're returning LazySeq. 错误确实说你正在返回LazySeq。 The problem is that it's trying to get stored in a Number, though I can't see where in this code segment. 问题是它试图存储在一个数字中,虽然我看不到这段代码中的位置。

Never mind. 没关系。 I found the problem. 我发现了这个问题。 There was an old version of the .class file lying around. 有一个旧版本的.class文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM