# maybeCreate

abstract fun <U : T?> maybeCreate(name: String, type: Class<U>): U(source)

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

This operation is eager, the element is realized before being returned.

#### Return

the found or created domain object, never `null`.

#### Since

1.11

#### Parameters

name

the name of the domain object to be created

type

the type of the domain object to be created

<U>

the type of the domain object to be created

#### Throws

org.gradle.api.InvalidUserDataException

if the container does not support creating a domain object with the specified type

java.lang.ClassCastException

if a domain object with the specified name exists with a different type