[groovy-user] Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor

4,524 views
Skip to first unread message

proggrammer

unread,
Jun 10, 2012, 3:08:46 PM6/10/12
to us...@groovy.codehaus.org
I am using IntelliJ for a simmple programming on Groovy

I have made groovy class named Object:

Object.groovy:

class Object {
def value
def square
Object(Integer x){
this.value = x
}
def getSquared(){
this.square = this.value*this.value
}
}

And an scipt: first.groovy:

def x=11
def object = new Object(x)

When I run First.groovy

I am getting the following error:
Caught: groovy.lang.GroovyRuntimeException: Could not find matching
constructor for: java.lang.Object(java.lang.Integer)
at FunctionSimple.run(First.groovy:6)

--
View this message in context: http://groovy.329449.n5.nabble.com/Caught-groovy-lang-GroovyRuntimeException-Could-not-find-matching-constructor-tp5710152.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Cédric Champeau

unread,
Jun 10, 2012, 3:14:24 PM6/10/12
to us...@groovy.codehaus.org
mmm, strange it works here (if both the class and the script are defined
in the same script). However creating a class which name is "Object",
that is to say the very same name as "java.lang.Object" which is the
base class for every class in java and groovy is probably not a good
idea, unless you put that class into its own package. Try renaming the
class.

C�dric

Le 10/06/2012 21:08, proggrammer a �crit :
--
C�dric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau

proggrammer

unread,
Jun 10, 2012, 4:29:48 PM6/10/12
to us...@groovy.codehaus.org
thanks for quick and perfect reply.. by changing the name of the class from
Object to Object1 gave the trick, these two are different files, though its
compiling fine, is it not expected? :)

--
View this message in context: http://groovy.329449.n5.nabble.com/Caught-groovy-lang-GroovyRuntimeException-Could-not-find-matching-constructor-tp5710152p5710157.html
Reply all
Reply to author
Forward
0 new messages