[英]ClassNotFoundException when trying to use class created using gen-class
我的代码:
(ns model.document
(:gen-class
:name model.document
:implements java.io.Serializable
:state "state"
:init "init"
:constructors {[String String String] []}
:methods [[getContent [] String]
[getTitle [] String]
[getUrl [] String]]))
(defn -init [content title url]
[[] (atom {:content content
:title title
:url url})])
(defn- get-field [this k]
(@(.state this) k))
(defn getContent [this]
(get-field this :content))
(defn getTitle [this]
(get-field this :title))
(defn getUrl [this]
(get-field this :url))
它的用途是:
(ns classification-server.classifier
(:require [model.document :refer :all]))
(new model.document "my-content" "my-title" "my-url")
而我却无济于事:
Caused by: java.lang.ClassNotFoundException: model.document, compiling:(classification_server/classifier.clj:13:12)
请帮助我。 你是我唯一的希望...
您发布的gen-class名称空间无法编译,因为:implements
规范需要符号的向量,而不是符号。 如果您将该行更改为
:implements [java.io.Serializable]
您将能够编译(和实例化)该类-但是,该类将不起作用,因为您的gen-class规范还存在其他问题,例如缺少前缀函数( -getContent
等)。
我建议您阅读gen-class文档并进一步简化问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.