Package com.anthropic.models.messages
Class MessageParam.Content
-
- All Implemented Interfaces:
public final class MessageParam.Content
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceMessageParam.Content.VisitorAn interface that defines how to map each variant of Content to a value of type T.
-
Method Summary
Modifier and Type Method Description final Optional<String>string()final Optional<List<ContentBlockParam>>blockParams()final BooleanisString()final BooleanisBlockParams()final StringasString()final List<ContentBlockParam>asBlockParams()final Optional<JsonValue>_json()final <T extends Any> Taccept(MessageParam.Content.Visitor<T> visitor)Maps this instance's current variant to a value of type T using the given visitor. final MessageParam.Contentvalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static MessageParam.ContentofString(String string)final static MessageParam.ContentofBlockParams(List<ContentBlockParam> blockParams)-
-
Method Detail
-
blockParams
final Optional<List<ContentBlockParam>> blockParams()
-
isBlockParams
final Boolean isBlockParams()
-
asBlockParams
final List<ContentBlockParam> asBlockParams()
-
accept
final <T extends Any> T accept(MessageParam.Content.Visitor<T> visitor)
Maps this instance's current variant to a value of type T using the given visitor.
Note that this method is not forwards compatible with new variants from the API, unless visitor overrides Visitor.unknown. To handle variants not known to this version of the SDK gracefully, consider overriding Visitor.unknown:
import com.anthropic.core.JsonValue; import java.util.Optional; Optional<String> result = content.accept(new Content.Visitor<Optional<String>>() { @Override public Optional<String> visitString(String string) { return Optional.of(string.toString()); } // ... @Override public Optional<String> unknown(JsonValue json) { // Or inspect the `json`. return Optional.empty(); } });
-
validate
final MessageParam.Content validate()
Validates that the types of all values in this object match their expected types recursively.
This method is not forwards compatible with new types from the API for existing fields.
-
ofString
final static MessageParam.Content ofString(String string)
-
ofBlockParams
final static MessageParam.Content ofBlockParams(List<ContentBlockParam> blockParams)
-
-
-
-