1

I did something like this

bindEagerSingleton(MyClass.class);

Can I do something like this

@SomeAnnotation
public class MyClass {}

Thank you!

johndoe
  • 4,387
  • 2
  • 25
  • 40
ddreian
  • 1,766
  • 5
  • 21
  • 29
  • As of Guice 4.2, there are no such annotations. – Olivier Grégoire Aug 06 '18 at 14:32
  • 1
    Thank you Oliver. That wat I was afraid of. Guice seems not to do any classpath scanning so that is why I think it's missing. – ddreian Aug 07 '18 at 07:25
  • The lack of classpath scanning has nothing to do with the lack of an eager singleton annotation. (I wouldn't even expect Guice to make any classpath scanning) The annotation is simply missing and that specific binding should be done by a module. If that's a feature you find useful, you might want to [ask for it](https://github.com/google/guice/issues) to the Guice team. – Olivier Grégoire Aug 07 '18 at 07:30
  • @OlivierGrégoire No, the lack of classpath scanning has very much to do with the lack of an eager singleton annotation. I've described the reason [in my answer](https://stackoverflow.com/a/51758536/1426891). – Jeff Bowman Aug 09 '18 at 03:50

1 Answers1

1

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.

Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251