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.
Advanced qualifiers
From the course: Java EE: Contexts and Dependency Injection
Advanced qualifiers
- [Instructor] We can have as many qualifiers as there are implementations. However, in a large system, this may be a very large number, and result in a lot of qualifier classes that do little other than mark injection points and implementations. Now, because qualifiers are annotations, they have annotation members, which we can use to reduce the number of qualifiers required. Annotations members are simply parameters that you pass to the annotation. So, If you were able to specify the bean type of either qualifier, then we would only need one qualifier, and this is possible if we make the annotation member an enum whose constant value represents the types you want to disambiguate. Okay, let's go to the ID and see how this might work. In this code snippet, the enum Type represent the EAN type. This is used by annotating the concrete implementation and the injection point and passing one of the enum constants. So I'm going to go to my EAN13Barcode and I'm going to annotate this class…
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.