Class ServiceReference<T>

  • Type Parameters:
    T - the generic type of the service class

    public class ServiceReference<T>
    extends Object
    Refers to a specific service. A service is identified by a name and its class. As such, several services of the same class may live in the application, even if they are declared as singleton, as long as they have a different name. If the service name is not important in your application, you may refer to a service only by its class via ofType(Class). In that case, the name of the service will be the name of the class as by Class.getName().

    This class implements equals(Object) and hashCode() on the name field only, meaning that in your application you are not supposed to use two references with the same name but different classes. However, as said earlier, the other way around is possible.

    See Also:
    of(String, Class), ofType(Class)
    • Method Detail

      • of

        public static <T> ServiceReference<T> of​(String serviceName,
                                                 Class<T> serviceClass)
        Creates a new ServiceReference with the given name and class.
        Type Parameters:
        T - the generic type of the service class
        Parameters:
        serviceName - the service name
        serviceClass - the service class
        Returns:
        a new ServiceReference
      • ofType

        public static <T> ServiceReference<T> ofType​(Class<T> serviceClass)
        Creates a new ServiceReference with the given class. The name of the class as by Class.getName() will be used as name for this reference.
        Type Parameters:
        T - the generic type of the service class
        Parameters:
        serviceClass - the service class
        Returns:
        a new ServiceReference
      • getServiceName

        public String getServiceName()
        Gets the name of the service that is referred to.
        Returns:
        the service name
      • getServiceClass

        public Class<T> getServiceClass()
        Gets the class of the service that is referred to.
        Returns:
        the service class
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object