OptionalLong

Represents a value that encapsulate the optional and value state of a Long in the Discord API. Specifically:

  • Missing - a Long field that was not present in the serialized entity.

  • Value - a Long field that was assigned a non-null value in the serialized entity.

Note that there is no nullable variant present. Use Long? or OptionalLong? for this case instead.

The base class is (de)serializable with kotlinx.serialization.

Note that kotlinx.serialization does not call serializers for values that are not present in the serialized format. Optional fields should have a default value of OptionalLong.Missing:

@Serializable
class DiscordUser(
val id: Long,
val username: String,
val bot: OptionalLong = OptionalLong.Missing
)

Inheritors

Types

Link copied to clipboard

Represents a Long field that was not present in the serialized entity.

Link copied to clipboard
class Value(val value: Long) : OptionalLong

Represents a field that was assigned a non-null value in the serialized entity. Equality and hashcode is implemented through its value.

Properties

Link copied to clipboard
Link copied to clipboard

returns null if this is null, calls OptionalLong.asNullable otherwise.

Link copied to clipboard
Link copied to clipboard

returns null if this is null, calls OptionalLong.asNullable otherwise.

Functions

Link copied to clipboard
fun orElse(default: Long): Long

returns default if the optional is Missing, or Value.value if is Value.

Link copied to clipboard
fun OptionalLong?.orElse(default: Long): Long

returns default if this is null, calls OptionalLong.asNullable otherwise.