I am a complete beginner with Guice, and trying to achieve the following:
public class Apple {
private final Integer size;
public Apple(Integer size) {
this.size = size;
}
}
public abstract class AppleModule {
protected AppleModule() {
ImmutableSet<Integer> sizes = ImmutableSet.of(1, 2, 3);
ImmutableSet<Apple> apples = sizes.stream().map(Apple::new).collect(ImmutableSet.toImmutableSet());
bind(new ImmutableSet<Apple>(){}).toInstance(apples);
}
}
so that every time I declare something like ImmutableSet<Apple> apppleBasket;
, I get the same list object injected. (but ImmutableSet
s of other types still behave as normal)
But code above does not work with bind(...)
saying Class must either be declared abstract or implement abstract method error
Note: I simplified the code I'm working on quite a bit while writing the question, so above might not compile out of box.