code: private static <T> T createObject(Class<T> interfaceClass) {
  
          ServiceLoader<T> loader = ServiceLoader.load(interfaceClass);
  
          T object = null;
          
          // Loop through the services.
          for (T loadedObject : loader) {
  
              // Check if a factory has not been found.
              if (object == null) {
  
                  // Set the factory.
                  object = loadedObject;
              } else {
                  throw new IllegalArgumentException("More than one MBean object found.");
              }
          }
  
          // Check if a object has not been found.
          if (object == null) {
              throw new IllegalArgumentException("No MBean object found.");
          }
  
          return object;
      }
docs: Create the MBean object.
  
  @param  interfaceClass  the MBean interface class.
  
  @return  the MBean object.