The Lookup is just a 'HashSet' where a single instance for your service is
added at startup (more or less).

That's the only relationship between the two. Creating further objects does
not add them to the Lookup, they are just normal Java objects created with
a constructor.

I wonder if you could use SharedClassObject although that's an old
deprecated class and I'm not sure if new instances auto-add themselves. You
can probably implement something like this yourself but it's an odd pattern.

--emi

dum., 13 oct. 2019, 19:31 Patrik Karlström <pat...@trixon.se> a scris:

> I feel somewhat stupid asking this one, but I just can't grip how to
> "publish" a "dynamically created" object so it will show up in lookupAll().
>
> This is a really small library I'm working on and the only NetBeans
> dependency I have is org-openide-util-lookup, if that matters at all.
>
> The following declared class:
> @ServiceProvider(service = Window.class)
> public class Left1bWindow extends Window {}
>
> shows up as expected when I do:
> var windows = new ArrayList<>(Lookup.getDefault().lookupAll(Window.class));
>
> but a simple object creation will not.
> Window someOtherWindow=new Window();
>
> What can I do to get the desired result?
>

Reply via email to