Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 41 java ee 8 select MyGreeting class NamedLiteral of northern get Both versions of the code will result in the MyGreeting1 instance being resolved The existence of the new NamedLiteral class makes it relatively easy to do this lookup Of course a bean might not be available for several reasons For example CDI 20 has made working with beans in a programmatic way much easier and it has enabled things that werent possible before in CDI a bean of the requested type might exist but not have the requested qualifier Or if the requested type is an interface it might be implemented by two or more classes which makes it impossible to return a single instance To test for any kind of failure to obtain a bean CDI 20 introduced the new isResolvable method The following example shows how this is used boolean isResolvable myGreetings select NamedLiteral of formal isResolvable Because there isnt a MyGreeting implementation available with a @ Named formal qualifier the result of the test above will be false Conclusion CDI 20 has made working with beans in a programmatic way much easier and it has enabled things that werent possible before in CDI such as combining interceptor bindings that are provided by a container or library with beans that are also provided by a container or library Weve seen that combining these provided interceptor bindings and beans takes a bit of code but that code should be easy to adapt for your own projects
You must have JavaScript enabled to view digital editions.