# AttributeContainer

interface AttributeContainer : HasAttributes(source)

An attribute container is a container of attributes, which are strongly typed named entities. Such a container is responsible for storing and getting attributes in a type safe way. In particular, attributes are strongly typed, meaning that when we get a value from the container, the returned value type is inferred from the type of the attribute. In a way, an attribute container is similar to a java.util.Map where the entry is a "typed String" and the value is of the string type. However, the set of methods available to the container is much more limited. It is not allowed to have two attributes with the same name but different types in the container.

#### Since

3.3

## Functions

addAllLater
Link copied to clipboard
@Incubating
abstract fun addAllLater(other: AttributeContainer): AttributeContainer
Lazily add all attributes from `other` to this container.
attribute
Link copied to clipboard
abstract fun <T> attribute(key: Attribute<T>, value: T): AttributeContainer
Sets an attribute value.
attributeProvider
Link copied to clipboard
abstract fun <T> attributeProvider(key: Attribute<T>, provider: Provider<out T>): AttributeContainer
Sets an attribute to have the same value as the given provider.
contains
Link copied to clipboard
abstract fun contains(key: Attribute<out Any>): Boolean
Tells if a specific attribute is found in this container.
getAttribute
Link copied to clipboard
@Nullable
abstract fun <T> getAttribute(key: Attribute<T>): @Nullable T
Returns the value of an attribute found in this container with the type specified by the given `key`, or `null` if this container doesn't have it.
getAttributes
Link copied to clipboard
abstract fun getAttributes(): AttributeContainer
Returns the attributes
isEmpty
Link copied to clipboard
abstract fun isEmpty(): Boolean
Returns true if this container is empty.
keySet
Link copied to clipboard
abstract fun keySet(): Set<Attribute<out Any>>
Returns the set of attribute keys of this container.
named
Link copied to clipboard
@Incubating
abstract fun <T : Named?> named(type: Class<T>, name: String): T
Creates a value of the given type for an Attribute.
named
Link copied to clipboard
@Incubating
inline fun <T : Named> AttributeContainer.named(name: String): T

Creates a simple immutable Named object of the given type and name.

@Incubating
inline fun <T : Named> AttributeContainer.named(type: KClass<T>, name: String): T

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.attributes.AttributeContainer.named.