When I run the main method in the Groovy code below, I get a groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.example.Person(java.lang.String, com.example.Pet). Why is that? I'm using the latest version of the Groovy/Grails Tool Suite.
Groovy:
package com.example
import groovy.transform.TypeChecked
@TypeChecked
class Test {
static main(args) {
Pet fido = new Pet(name: 'Fido', nickname: 'Scruffy')
Person dave = new Person('Dave', fido)
}
}
@TypeChecked
class Pet {
String name
String nickname
}
Java:
package com.example;
public class Person {
private String name;
private Pet pet;
public Person(String name, Pet pet) {
this.name = name;
this.pet = pet;
}
}
Make sure you compile and run in this order:
groovyc Pet.groovyjavac Person.javagroovyc Test.groovy
groovy Test
It works for me as expected if the above order is followed. In GGTS make sure you are compiling/building the project as expected to make sure dependent classes are built.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With