load(Class, ClassLoader): This method is available in java.util.ServiceLoader class of Java.
Syntax:
<K> ServiceLoader<K> java.util.ServiceLoader.load(Class<K> service, ClassLoader loader)
This method takes two arguments. This method creates a new service loader for the given service. The service loader uses the given class loader as the starting point to locate service providers for the service.
Parameters: Two parameters are required for this method.
service: The interface or abstract class representing the service.
loader: The class loader to be used to load provider-configuration files and provider classes, or null if the system classloader (or, failing that, the bootstrap class loader) is to be used.
Returns: A new service loader.
Throws:
ServiceConfigurationError - if the service type is not accessible to the caller or the caller is in an explicit module and its module descriptor does not declare that it uses service.
Approach
Java
import java.util.ServiceLoader;public class ServiceLoaderload2 {public static void main(String[] args) {System.out.println(ServiceLoader.load(String.class,new ClassLoader() {}));}}
Output:
java.util.ServiceLoader[java.lang.String]
No comments:
Post a Comment