@SuppressWarnings("unchecked") public <T> T getInstance(String identifier, Class<T> type, Object... args) { Util.requireNonNull(type, "type"); if (!type.isInterface()) { throw new IllegalArgumentException("type must be an interface"); } Map<String, Class<?>> classes = implementations.get(type); if (classes == null) { classes = findImplementations(type); implementations.put(type, classes); } if (classes.size() > 0) { Class<?> target = classes.get(identifier); return (T) constructInstance(target, args); } if (getType() == PlatformType.Headless) { // Create default implementation on headless platforms. return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, (proxy, method, args1) -> { Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { return getPrimitiveNullValue(returnType); } return null; }); } throw new IllegalArgumentException("No class found that implements " + type.getSimpleName()); }
@SuppressWarnings("unchecked") public <T> T getInstance(String identifier, Class<T> type, Object... args) { Util.requireNonNull(type, "type"); if (!type.isInterface()) { throw new IllegalArgumentException("type must be an interface"); } Map<String, Class<?>> classes = implementations.get(type); if (classes == null) { classes = findImplementations(type); implementations.put(type, classes); } if (classes.size() > 0) { Class<?> target = classes.get(identifier); return (T) constructInstance(target, args); } if (getType() == PlatformType.Headless) { // Create default implementation on headless platforms. return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, (proxy, method, args1) -> { Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { return getPrimitiveNullValue(returnType); } return null; }); } throw new IllegalArgumentException("No class found that implements " + type.getSimpleName()); }
Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { return getPrimitiveNullValue(returnType);