Groovy找不到匹配的构造函数

时间:2015-07-16 21:42:32

标签: java intellij-idea groovy

有人可以向我解释为什么这段简单的代码无法编译?

Node.groovy

class Node{

    Integer key
    String value

    Node leftNode
    Node rightNode

    Node(){}

    Node(Integer k, String v){
        this.key = k
        this.value = v
    }

}

BinaryTree.groovy

class BinaryTree{

    Node root;

    def addNode(k, v){

        def newNode = new Node(k,v)

        if(!root){
            root = newNode
        }else{
            Node currentNode = root
            Node parent

            while(true){
                parent = currentNode
                if(k < currentNode.key) {
                    currentNode = currentNode.leftNode
                    if(!currentNode){
                        parent.leftNode = newNode
                        return
                    }
                } else {
                    currentNode = currentNode.rightNode
                    if(!currentNode){
                        parent.rightNode = newNode
                        return
                    }
                }
            }
        }
    }

    def inOrderTraversal(def node, def silent){
        if(node){
            inOrderTraversal(node.leftNode)
            !silent ?: println("Node ${node.dump()}")
            inOrderTraversal(node.rightNode)
        }
    }


}

Main.groovy

//Test the binaryTree Project
binaryTree = new BinaryTree();

binaryTree.addNode(45, "v1")
binaryTree.addNode(60, "v4")
binaryTree.addNode(12, "v3")
binaryTree.addNode(32, "v9")
binaryTree.addNode(415, "v7")

binaryTree.inOrderTraversal(binaryTree.root, false)

3个简单文件。这是我在intellij中按下播放或者尝试运行时得到的结果:groovy -cp ./src src/Main.groovy

Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: groovy.util.Node(java.lang.Integer, java.lang.String)
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: groovy.util.Node(java.lang.Integer, java.lang.String)
    at BinaryTree.addNode(BinaryTree.groovy:7)
    at BinaryTree$addNode.call(Unknown Source)
    at Main.run(Main.groovy:4)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Node中的构造函数对我来说很好。

我正在使用Java 8和groovy 2.4

由于

0 个答案:

没有答案