javacdiguicejava-annotationsguice-3

Is there any annotation equivalent for Guice's bindEagerSingleton()?


I did something like this

bindEagerSingleton(MyClass.class);

Can I do something like this

@SomeAnnotation
public class MyClass {}

Thank you!


Solution

  • As discussed in the comments, there is no such annotation, and you are correct that classpath scanning is the culprit: Guice does not conduct classpath scanning, so even if there were an @EagerSingleton annotation, Guice still wouldn't encounter a reference to the class (or its fully-qualified class name) until you request it. At that point it would no longer be eager.