local variable type inference changes (#1035)
local variable type inference changes for design pattern service locator
This commit is contained in:
parent
f7a53f2d17
commit
58d8fa1758
@ -45,7 +45,7 @@ public class App {
|
|||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Service service = ServiceLocator.getService("jndi/serviceA");
|
var service = ServiceLocator.getService("jndi/serviceA");
|
||||||
service.execute();
|
service.execute();
|
||||||
service = ServiceLocator.getService("jndi/serviceB");
|
service = ServiceLocator.getService("jndi/serviceB");
|
||||||
service.execute();
|
service.execute();
|
||||||
|
@ -45,7 +45,7 @@ public final class ServiceLocator {
|
|||||||
* @return {@link Service}
|
* @return {@link Service}
|
||||||
*/
|
*/
|
||||||
public static Service getService(String serviceJndiName) {
|
public static Service getService(String serviceJndiName) {
|
||||||
Service serviceObj = serviceCache.getService(serviceJndiName);
|
var serviceObj = serviceCache.getService(serviceJndiName);
|
||||||
if (serviceObj != null) {
|
if (serviceObj != null) {
|
||||||
return serviceObj;
|
return serviceObj;
|
||||||
} else {
|
} else {
|
||||||
@ -53,7 +53,7 @@ public final class ServiceLocator {
|
|||||||
* If we are unable to retrive anything from cache, then lookup the service and add it in the
|
* If we are unable to retrive anything from cache, then lookup the service and add it in the
|
||||||
* cache map
|
* cache map
|
||||||
*/
|
*/
|
||||||
InitContext ctx = new InitContext();
|
var ctx = new InitContext();
|
||||||
serviceObj = (Service) ctx.lookup(serviceJndiName);
|
serviceObj = (Service) ctx.lookup(serviceJndiName);
|
||||||
if (serviceObj != null) { // Only cache a service if it actually exists
|
if (serviceObj != null) { // Only cache a service if it actually exists
|
||||||
serviceCache.addService(serviceObj);
|
serviceCache.addService(serviceObj);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user