From the course: Java EE: Contexts and Dependency Injection
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Combine producers and qualifiers
From the course: Java EE: Contexts and Dependency Injection
Combine producers and qualifiers
- [Instructor] Earlier on in this course, you learned about qualifiers, and how they can be used to disambiguate between instances of the same type. Well you can use qualifiers with producer methods too. Let's go to the IDE, and look at how to use qualifiers and custom annotations together. Here I have a situation where I have a class, called Tailor, that's using an instance called Shirt. Now simply what this does, in the method makeShirt, is to print out the color of the shirt. Here I have the shirt class, and it's a very simple class. It has one property which is color. Here's the BootStrap class, it just uses an instance of the Tailor class, and calls the makeSuit method. So let's execute this and see what happens. And as you can see, the color is null. Well that's okay, we haven't actually set a color. Now the ways we can set a color, are by setting the color in the actual class itself, or by setting the color here in this class. So we could set the color in the makeSuit method…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.