users@hk2.java.net

ServiceLocator.getService(Class<?>) vs createAndInitialize(Class<?>)

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Thu, 17 Apr 2014 23:19:21 -0400

Hi,

What's the difference between ServiceLocator.getService(Class<?>) and
createAndInitialize(Class<?>) methods? I read the Javadoc over and over
but I don't see the difference. Doesn't getService() also inject and
post-construct the returned instance?

I notice one of Jersey's methods does this:

             T component = serviceLocator.getService(clazz);
             return component == null ?
serviceLocator.createAndInitialize(clazz) : component;

Why would getService() return null but createAndInitialize() work?

Thanks,
Gili