groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: Simple question.. how to call a java class method in Groovy Script
Date Mon, 22 May 2017 23:48:07 GMT
On 22.05.2017 20:13, RJ wrote:
> Thanks for the response, Jochen.  Tried your suggestion, it doesn't like it:
>
> 2017-05-22 14:06:15,871 ERROR - <groovy.lang.MissingMethodException: No
> signature of method: static com.example.auth.principal.getId() is
> applicable for argument types: () values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
> wait(long), grep(java.lang.Object)>
> org.codehaus.groovy.runtime.InvokerInvocationException:
> groovy.lang.MissingMethodException: No signature of method: static
> com.example.auth.principal.getId() is applicable for argument types: ()
> values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
> wait(long), grep(java.lang.Object)
>
> We try something like this in Java.. Whats the equivalent in Groovy Script ?
>
> import com.example.auth.principal;
> public String1 abcd(final principal Principal){
> return Principal.getId();
> }

so you are telling me this Java program compiles and runs without error, 
while the same program (just taken as is) in Groovy fails? I mean that 
program there does not look complete of course. But I really wonder 
about Principal.getId() here and principal.getId() in the Groovy 
program. For me it means you are invoking the method getId on the 
instance Principal (frankly, that those classes do not follow the Java 
conventions for class naming makes it quite difficult to understand what 
is what) of the class principal, while in Groovy you call getId() 
directly on the class principal. If getId() is an instance method, then 
this requires an instance of principal for the call.

bye Jochen


Mime
View raw message