I’m new to Groovy.
Given the following interface:
public interface EventSubscriber {
void onEvent(Achiever achiever, AchievementEvent event);
}
and this piece of Groovy code which consumes it:
List<EventSubscriber> subscribers;
public void publishEvent(Achiever achiever, AchievementEvent event) {
subscribers.each { it.onEvent(achiever, event) }
}
This code works fine, however I get no code hinting against it, despite it being strongly typed to EventSubscriber.
Is there a way to acheive this typing in groovy, or is that just not the groovy way?
“code hinting” is not a feature of the language, but of the IDE. My guess is that you’re using eclipse, whose Groovy support is steadily improving, but not perfect. IntelliJ IDEA is supposed to have better Groovy support, so you may want to try that.
That being said, the “groovy way” would be to use duck typing rather than interfaces, and few explicit type declarations in general.