@SuppressWarnings("unchecked")
    public final <T extends Trait> Optional<T> getTrait(Class<T> traitClass) {
        for (Trait trait : traits.values()) {
            if (traitClass.isInstance(trait)) {
                return Optional.of((T) trait);
            }
        }

        return Optional.empty();
    }
Attempt to retrieve a specific {@link Trait} by class from the shape.

<p>The first trait instance found matching the given type is returned.

@param traitClass Trait class to retrieve.
@param <T> The instance of the trait to retrieve.
@return Returns the matching trait.
smithy-model/src/main/java/software/amazon/smithy/model/shapes/Shape.java