gradle
8.2

# withType

abstract fun <S : T?> withType(type: Class<S>): DomainObjectCollection<S>

Returns a collection containing the objects in this collection of the given type. The returned collection is live, so that when matching objects are later added to this collection, they are also visible in the filtered collection.

#### Return

The matching objects. Returns an empty collection if there are no such objects in this collection.

#### Parameters

type

The type of objects to find.

abstract fun <S : T?> withType(type: Class<S>, configureAction: Action<out Any>): DomainObjectCollection<S>

Returns a collection containing the objects in this collection of the given type. Equivalent to calling `withType(type).all(configureAction)`

#### Return

The matching objects. Returns an empty collection if there are no such objects in this collection.

#### Parameters

type

The type of objects to find.

configureAction

The action to execute for each object in the resulting collection.

abstract fun <S : T?> withType(type: Class<S>, @DelegatesTo(genericTypeIndex = 0) configureClosure: Closure): DomainObjectCollection<S>

Returns a collection containing the objects in this collection of the given type. Equivalent to calling `withType(type).all(configureClosure)`.

#### Return

The matching objects. Returns an empty collection if there are no such objects in this collection.

#### Parameters

type

The type of objects to find.

configureClosure

The closure to execute for each object in the resulting collection.