什么是错误的原因Clojure:获取没有匹配Ctor发现,而试图填充Java类从Clojure? [英] What is the cause of the error Clojure: Get No Matching Ctor found while trying to populate a Java class from Clojure?

查看:98
本文介绍了什么是错误的原因Clojure:获取没有匹配Ctor发现,而试图填充Java类从Clojure?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解决为什么我得到没有匹配Ctor找到,而试图填充Java类从Clojure。

I want to fix why I am getting No Matching Ctor found while trying to populate a Java class from Clojure.

我想从Clojure填充这个类。 / p>

I want to populate this class from Clojure.

import java.util.Date;

public class Account {
    Account() { acct_num = 0; 
                trans_type = 'U';
                trans_amt = 0.00;
                cur_bal = 0.00;
                last_update = null;
               }

    public int acct_num = 0;
    public char trans_type;
    public double trans_amt = 0.00;
    public double cur_bal = 0.00;
    public Date last_update;
}

我可以导入类:

ba2-app =>(ns ba2-app(:import Account))
帐户

ba2-app=> (ns ba2-app (:import Account)) Account

但是当我去填充它得到此错误:

but when I go to populate it, I get this error:

ba2-app =>(:使用java.util.Date)
nil
ba2-app => 1000 \C 100.00 0.00(java.util.Date。12/21/2011))
java.lang.IllegalArgumentException:没有为类Account找到匹配的ctor(NO_SOURCE_FILE:9)
ba2- app =>

ba2-app=> (:use java.util.Date) nil ba2-app=> (Account. 1000 \C 100.00 0.00 (java.util.Date. "12/21/2011")) java.lang.IllegalArgumentException: No matching ctor found for class Account (NO_SOURCE_FILE:9) ba2-app=>

我遵循了以下建议:使用Clojure使用蛋糕构建Java - 获取使用我的Clojure代码内置的Java类。这些建议非常有帮助,因为我现在可以构建Java类。

I followed these suggestions -- Building Java In With Clojure Using Cake -- to get the Java class built in with my Clojure code. The suggestions which were very helpful, because I can now build the Java class.

任何指针或建议都会有所帮助。我知道类成员应该是私有的,但这是测试一个更大的项目。

Any pointers or suggestions would be helpful. I know the class members should be private, but this is to test out a larger project.

推荐答案

公共访问修饰符。此外,你的构造函数不接受任何参数,而只是设置一些成员的一些值。因此,您现在实际上只能调用它:(Account。)(如果它是公开的)。

Make the constructor public with the public access modifier. Also your constructor doesn't accept any args, but just sets a bunch of members to some values. So you can now actually only call it like: (Account.) (if it were public).

你想使用这样的构造函数:(Account。1000 \C 100.00 0.00(java.util.Date。12/21/2011))必须添加一个接受这些类型的参数的构造函数:

When you want to use a constructor like this: (Account. 1000 \C 100.00 0.00 (java.util.Date. "12/21/2011")) you'll have to add a constructor that accepts these types of arguments:

    public Account(int a, char c, double d1, double d2, Date date) { 
      acct_num = a; 
      trans_type = c;
      trans_amt = d1;
      cur_bal = d2;
      last_update = date;
    }

这篇关于什么是错误的原因Clojure:获取没有匹配Ctor发现,而试图填充Java类从Clojure?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆