peugas55
peugas55

Reputation: 73

Importing a class in Groovy

I'm trying to import another class in groovy, but to no sucess so far. I've tried to run this example:

http://www.chatsiri.com/?q=node/163

didn't work.

Caught: groovy.lang.MissingPropertyException: No such property: readData

Upvotes: 0

Views: 3718

Answers (1)

jjchiw
jjchiw

Reputation: 4425

There is a lot of typos in the Code, and it does not follow the Convention for the java classes like (and the article is from 2007):

  • Class instead of class
  • Class name starting with lowercase
  • printIn? instead of println
  • System.In.readString()??? Not in the actual Groovy JDK

Anyways, just creating new classes Foo and Bar to corraborate what the blog is saying.....

File Bar.groovy

class Bar{
    def print(){
        println "Bar"
    }

    def add(a, b){
        return a+b;
    }

}

File Foo.groovy

def b = new Bar()
b.print()
println b.add(1,2)

Runing

>groovy Foo.groovy
Bar
3

Upvotes: 2

Related Questions