You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Ivo K. Koga" <iv...@gmail.com> on 2006/12/18 16:45:14 UTC
Can I instantiate a class inside a bundle?
Hi all,
I'm trying to instantiate a class from one bundle inside another. Can I do
it? Maybe exporting from one and import from another. Is that the point?
Regards,
Ivo K. Koga
--
Msc. Candidate in Computer Networks at Universidade Salvador/BA/Brazil
Measurement WG - RNP/Brazil
Re: Can I instantiate a class inside a bundle?
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Ivo K. Koga wrote:
> I'm trying to instantiate a class from one bundle inside another. Can
> I do
> it? Maybe exporting from one and import from another. Is that the point?
Well, you can do Bundle.loadClass() on the bundle from which you wish to
load the class and then just do Class.newInstance() on it. However,
unless you have imported the class, then you will not be able to cast to
the class directly and will have to use reflection.
If you import the class' package from the bundle, then there is nothing
special you need to do, just the normal "new MyClass"...
-> richard
Re: Can I instantiate a class inside a bundle?
Posted by Marcel Offermans <ma...@luminis.nl>.
On Dec 18, 2006, at 16:45 , Ivo K. Koga wrote:
> I'm trying to instantiate a class from one bundle inside another.
> Can I do
> it? Maybe exporting from one and import from another. Is that the
> point?
Yes, you can do that by exporting and importing it.
Alternatively, you might want to consider using a factory pattern
here (for example a service that creates the instance for you). Of
course this depends on your exact use case (which I know nothing of,
so this is just a shot in the dark :) ).
Greetings, Marcel