简体   繁体   English

无法从Clojure调用实例方法。

[英]Unable to call an instance method from Clojure.

I'm completely new to Java and clojure. 我对Java和clojure完全陌生。 But with previous experience in common lisp, I thought I would give clojure a try. 但是根据以前对普通口齿不清的经验,我认为我可以尝试一下clojure。 I'm unable to figure out few very basic things. 我无法弄清一些非常基本的东西。

This is the actual Java code. 这是实际的Java代码。

import syntaxtree.*;
import visitor.*;

public class Main {
    public static void main(String [] args) {
    try {
        Node root = new MicroJavaParser(System.in).Goal();
        System.out.println("Program parsed successfully");
    }
    catch (ParseException e) {
        System.out.println(e.toString());
    }
    }
} 

When I run this code, the outcome is as expected. 当我运行此代码时,结果是预期的。

└──╼ java Main < ../input/Factorial.java 
Program parsed successfully

In Clojure I tried this : 在Clojure中,我尝试了以下方法:

(ns clj-assign2.core)

(defn -main
  []
  (def root
    (.Goal
     (MicroJavaParser. (. System in))))
  (println "Successfully parsed"))

But when this code is run, the following exception is raised : 但是,当运行此代码时,将引发以下异常:

└──╼ lein run < ../assign2/input/Factorial.java 
Exception in thread "main" java.lang.IllegalArgumentException: No matching field found: Goal for class MicroJavaParser
    at clojure.lang.Reflector.getInstanceField(Reflector.java:271)
    at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:300)
    at clj_assign2.core$_main.invoke(core.clj:7)
< --- snipped --- >

What am I doing wrong here? 我在这里做错了什么?

也许您的Clojure程序中缺少导入语句?

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

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