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
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Service service = ServiceLocator.getService("jndi/serviceA");
|
||||
var service = ServiceLocator.getService("jndi/serviceA");
|
||||
service.execute();
|
||||
service = ServiceLocator.getService("jndi/serviceB");
|
||||
service.execute();
|
||||
|
@ -45,7 +45,7 @@ public final class ServiceLocator {
|
||||
* @return {@link Service}
|
||||
*/
|
||||
public static Service getService(String serviceJndiName) {
|
||||
Service serviceObj = serviceCache.getService(serviceJndiName);
|
||||
var serviceObj = serviceCache.getService(serviceJndiName);
|
||||
if (serviceObj != null) {
|
||||
return serviceObj;
|
||||
} 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
|
||||
* cache map
|
||||
*/
|
||||
InitContext ctx = new InitContext();
|
||||
var ctx = new InitContext();
|
||||
serviceObj = (Service) ctx.lookup(serviceJndiName);
|
||||
if (serviceObj != null) { // Only cache a service if it actually exists
|
||||
serviceCache.addService(serviceObj);
|
||||
|
Loading…
x
Reference in New Issue
Block a user