0 Replies Latest reply on Nov 25, 2010 12:15 AM by mtaal

    Howto use Instance.select with classes with inheritance without getting ambiguity issues?

    mtaal
      Hi,
      I have a case where class names are passed in as Strings and I want to get an instance of the bean using the classname. I use an Instance object like this:

        @Inject
        @Any
        private Instance<Component> components;

      and then in my code I do something like this:
      Class<?> clz = MyClassLoader.loadClass(clzName):
      Component component = components.select(clz).get();

      Now this fails if there is inheritance and both the super and subclass can be passed in as the classname. If I pass in the super class then Weld does not know what to create (the super or subclass), I am getting an exception on ambiguous etc..

      I understand where this exception is coming from, but I really want to have an instance of the class I pass in and not of any subclass.

      Is there a special qualifier (or another way) I can pass into the select method to tell Weld that I really want an instance of the passed class and not of a subclass (so that there is no ambiguity)? Or is there another way to create an instance of a bean without using qualifiers?

      I can qualify the classes but I only get the classnames passed in (no qualifier) so I don't know what qualifier to use when calling the select method. And imho it is not necessary either, I just want to get an instance of the class I pass in and not of a subclass.

      Thanks for any pointers or help!

      gr. Martin