开发者

Importing a class in Groovy

开发者 https://www.devze.com 2023-04-07 04:38 出处:网络
I\'m trying to import another class in groovy, but to no sucess so far. I\'ve tried to run this example:

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消