Reputation: 8913
I have a groovy class
@Immutable
class StatusCode {
final int statusCode
}
I want to create an object of this class in another Java class say, Test.Java. But when I use,
public class Test{
StatusCode statusCode;
public void setStatusCode(int statusCode)
{
this.statusCode = new StatusCode(statusCode);
}
}
It says the constructor is missing. How do I instantiate this object ?
Upvotes: 0
Views: 1070
Reputation: 1642
Groovy code can be compiled into Java bytecode using groovyc. This will give you a valid Java class you can reference from any other Java class. You do still need to have the groovy runtime JAR on your claspath.
It's possible the Groovy compiler will generate the desired constructor for you, but I'm not sure. If not, you'd need to explicitly code it in the Groovy class.
Upvotes: 1