org.gradle.api

## Interface PolymorphicDomainObjectContainer<T>

- Type Parameters:
    `T` - the (base) type of domain objects in the container
  All Superinterfaces:
    Collection<T>, org.gradle.util.Configurable<NamedDomainObjectContainer<T>>, DomainObjectCollection<T>, Iterable<T>, NamedDomainObjectCollection<T>, NamedDomainObjectContainer<T>, NamedDomainObjectSet<T>, Set<T>
  All Known Subinterfaces:
    BinaryContainer, ExtensiblePolymorphicDomainObjectContainer<T>, FunctionalSourceSet, PublicationContainer, TaskContainer, ToolChainRegistry

      @Incubating
      public interface PolymorphicDomainObjectContainer<T>
      extends NamedDomainObjectContainer<T>

  A `NamedDomainObjectContainer` that allows to create domain objects with different types.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `<U extends T> U` | `create(String name, Class<U> type)` Creates a domain object with the specified name and type, and adds it to the container.
    `<U extends T> U` | `create(String name, Class<U> type, Action<? super U> configuration)` Creates a domain object with the specified name and type, adds it to the container, and configures it with the specified action.

    - ### Methods inherited from interface org.gradle.api.NamedDomainObjectContainer

      `configure, create, create, create, maybeCreate`

    - ### Methods inherited from interface org.gradle.api.NamedDomainObjectSet

      `findAll, matching, matching, withType`

    - ### Methods inherited from interface org.gradle.api.NamedDomainObjectCollection

      `add, addAll, addRule, addRule, findByName, getAsMap, getAt, getByName, getByName, getNamer, getNames, getRules`

    - ### Methods inherited from interface org.gradle.api.DomainObjectCollection

      `all, all, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withType`

    - ### Methods inherited from interface java.util.Collection

      `clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray`

    - ### Methods inherited from interface java.util.Set

      `add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray`

- - ### Method Detail

    - #### create

          <U extends T> U create(String name,
                               Class<U> type)
                             throws InvalidUserDataException

      Creates a domain object with the specified name and type, and adds it to the container.
      Type Parameters:
        `U` - the type of the domain object to be created
      Parameters:
        `name` - the name of the domain object to be created
        `type` - the type of the domain object to be created
      Returns:
        the created domain object
      Throws:
        `InvalidUserDataException` - if a domain object with the specified name already exists or the container does not support creating a domain object with the specified type

    - #### create

          <U extends T> U create(String name,
                               Class<U> type,
                               Action<? super U> configuration)
                             throws InvalidUserDataException

      Creates a domain object with the specified name and type, adds it to the container, and configures it with the specified action.
      Type Parameters:
        `U` - the type of the domain object to be created
      Parameters:
        `name` - the name of the domain object to be created
        `type` - the type of the domain object to be created
        `configuration` - an action for configuring the domain object
      Returns:
        the created domain object
      Throws:
        `InvalidUserDataException` - if a domain object with the specified name already exists or the container does not support creating a domain object with the specified type