Paul Reiners
Paul Reiners

Reputation: 7894

ClassCastException when returning LazySeq from Clojure to Java

I have Clojure function that returns a LazySeq. When I run this function from the REPL, it works just fine. However, if I try to call the same function from Java code like this:

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
    :name com.acme.forecast.core
    :methods [#^{:static true} [runforecast [String String] clojure.lang.LazySeq]])

What is going wrong here?

Upvotes: 3

Views: 403

Answers (2)

Paul Reiners
Paul Reiners

Reputation: 7894

Never mind. I found the problem. There was an old version of the .class file lying around.

Upvotes: 1

Thomas
Thomas

Reputation: 5094

The error does say you're returning LazySeq. The problem is that it's trying to get stored in a Number, though I can't see where in this code segment.

Upvotes: 3

Related Questions