Package: org.gradle.api

## [Java] Interface PolymorphicDomainObjectContainer<T>

- org.gradle.api.NamedDomainObjectCollection

- All Superinterfaces:
    NamedDomainObjectSet, NamedDomainObjectContainer, Iterable, DomainObjectCollection, Collection, NamedDomainObjectCollection

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

  Parameters:
    `` - the (base) type of domain objects in the container

- - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `NamedDomainObjectContainer<U>` | `containerWithType(Class<U> type)` Creates a regular container that wraps the polymorphic container presenting all elements of a specified type.
    `U` | `create(String name, Class<U> type)` Creates a domain object with the specified name and type, and adds it to the container.
    `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.
    `U` | `maybeCreate(String name, Class<U> type)` Looks for an item with the given name and type, creating and adding it to this container if it does not exist.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `interface NamedDomainObjectContainer` | `configure, create, create, create, maybeCreate`
    `interface NamedDomainObjectSet` | `findAll, matching, matching, withType`
    `interface org.gradle.util.Configurable` | `org.gradle.util.Configurable#configure(groovy.lang.Closure)`

- - ### Method Detail

    - #### public NamedDomainObjectContainer<U> containerWithType(Class<U> type)

      Creates a regular container that wraps the polymorphic container presenting all elements of a specified type.

      Parameters:
        `type` - the type of the container elements
        `` - the type of the container elements
      Returns:
        a NamedDomainObjectContainer providing access to elements of type U.

    - #### public U create(String name, Class<U> type)

      Creates a domain object with the specified name and type, and adds it to the container.

      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
      Parameters:
        `name` - the name of the domain object to be created
        `type` - the type of the domain object to be created
        `` - the type of the domain object to be created
      Returns:
        the created domain object

    - #### public 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.

      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
      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
        `` - the type of the domain object to be created
      Returns:
        the created domain object

    - #### @Incubating public U maybeCreate(String name, Class<U> type)

      Looks for an item with the given name and type, creating and adding it to this container if it does not exist.

      throws:
        InvalidUserDataException if the container does not support creating a domain object with the specified type
      throws:
        ClassCastException if a domain object with the specified name exists with a different type
      Parameters:
        `name` - the name of the domain object to be created
        `type` - the type of the domain object to be created
        `` - the type of the domain object to be created
      Returns:
        the found or created domain object, never `null`.