Вопрос

For Instance, I have a class like this:

class firstOne{

    ....
    def A (){

    }

}

class secondOne{

    // I need to call and use method A from class firstOne
    // even I get error if I try to follow Java like calls
    // firstOne method = new firstOne();
    // method.A()   
}

I already tried http://groovy.codehaus.org/Scripts+and+Classes and http://groovy.codehaus.org/Groovy+Beans but no way. Any kind of suggestion or examples would be really helpful.

Это было полезно?

Решение

I don't see any problem in this:

class FirstOne {

    def a() {
        println "a"
    }
}

class SecondOne {

    def b() {
        new FirstOne().a()
        println "b"
    }
}

new FirstOne().a()
println("")
new SecondOne().b()

Output:

a
a
b

Другие советы

This is not specific to Groovy/Grails:

firstOne first = new firstOne()
first.A()

Also you should capitalize the first letter of classes, but not methods (as is best practice in Java).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top