java - Groovy could not find matching constructor -
could explain me why simple piece of code not compile?
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 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 simple files. when press play in intellij, or when try run this: groovy -cp ./src src/main.groovy
caught: groovy.lang.groovyruntimeexception: not find matching constructor for: groovy.util.node(java.lang.integer, java.lang.string) groovy.lang.groovyruntimeexception: not find matching constructor for: groovy.util.node(java.lang.integer, java.lang.string) @ binarytree.addnode(binarytree.groovy:7) @ binarytree$addnode.call(unknown source) @ main.run(main.groovy:4) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140)
the constructor in node looks fine me.
i using java 8 , groovy 2.4
thanks
Comments
Post a Comment