Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个由 Google Guice 创建的单例服务。该服务具有注册/注销侦听器方法。一些服务方法向注册的侦听器发送通知。Guice 有没有办法在引导程序中取消/注册一些听众?我还希望有可能在运行时添加侦听器。
谢谢, Soccerrash
使用提供者(或提供方法)
@Provides @Singleton public YourService provideService(ListenerA a, ListernerB b) { YourService service = new YourService(); service.register(a); service.register(b); return service; }
您可以稍后手动添加Listerner c。