ServiceLoader loadInstalled(Class) in Java

loadInstalled(Class): This method is available in java.util.ServiceLoader class of Java.

Syntax:

<K> ServiceLoader<K> java.util.ServiceLoader.loadInstalled(Class<K> service)

This method takes one argument. This method creates a new service loader for the given service type, using the platform class loader.

Parameters: One parameter is required for this method.

service: The interface or abstract class representing the service.

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 ServiceLoaderloadInstalled {
    public static void main(String[] args) {

        System.out.println(ServiceLoader.
loadInstalled(String.class));
    }

}

Output:

java.util.ServiceLoader[java.lang.String]


No comments:

Post a Comment