Stay organized with collections
Save and categorize content based on your preferences.
publicclassLazyFieldLite
LazyFieldLite encapsulates the logic of lazily parsing message fields. It stores the message in a
ByteString initially and then parses it on-demand.
LazyFieldLite is thread-compatible: concurrent reads are safe once the proto that this
LazyFieldLite is a part of is no longer being mutated by its Builder. However, explicit
synchronization is needed under read/write situations.
When a LazyFieldLite is used in the context of a MessageLite object, its behavior is
considered to be immutable and none of the setter methods in its API are expected to be invoked.
All of the getters are expected to be thread-safe. When used in the context of a
MessageLite.Builder, setters can be invoked, but there is no guarantee of thread safety.
TODO(yatin,dweis): Consider splitting this class's functionality and put the mutable methods
into a separate builder class to allow us to give stronger compile-time guarantees.
This class is internal implementation detail of the protobuf library, so you don't need to use
it directly.
Constructs a LazyFieldLite instance with a value. The LazyFieldLite may not be able to parse
the extensions in the value as it has no ExtensionRegistry.
Due to the optional field can be duplicated at the end of serialized bytes, which will make the
serialized size changed after LazyField parsed. Be careful when using this method.
Merges another instance's contents. In some cases may drop some extensions if both fields
contain data. If the other field has an ExtensionRegistry but this does not, then this
field will copy over that ExtensionRegistry.
LazyField is not thread-safe for write access. Synchronizations are needed under read/write
situations.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class LazyFieldLite (3.19.4)\n\n public class LazyFieldLite\n\nLazyFieldLite encapsulates the logic of lazily parsing message fields. It stores the message in a\nByteString initially and then parses it on-demand.\n\nLazyFieldLite is thread-compatible: concurrent reads are safe once the proto that this\nLazyFieldLite is a part of is no longer being mutated by its Builder. However, explicit\nsynchronization is needed under read/write situations.\n\nWhen a LazyFieldLite is used in the context of a MessageLite object, its behavior is\nconsidered to be immutable and none of the setter methods in its API are expected to be invoked.\nAll of the getters are expected to be thread-safe. When used in the context of a\nMessageLite.Builder, setters can be invoked, but there is no guarantee of thread safety.\n\nTODO(yatin,dweis): Consider splitting this class's functionality and put the mutable methods\ninto a separate builder class to allow us to give stronger compile-time guarantees.\n\nThis class is internal implementation detail of the protobuf library, so you don't need to use\nit directly. \n\nInheritance\n-----------\n\n[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e LazyFieldLite \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### fromValue(MessageLite value)\n\n public static LazyFieldLite fromValue(MessageLite value)\n\nConstructs a LazyFieldLite instance with a value. The LazyFieldLite may not be able to parse\nthe extensions in the value as it has no ExtensionRegistry.\n\nConstructors\n------------\n\n### LazyFieldLite()\n\n public LazyFieldLite()\n\nConstructs a LazyFieldLite with no contents, and no ability to parse extensions.\n\n### LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes)\n\n public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes)\n\nConstructs a LazyFieldLite with bytes that will be parsed lazily.\n\nFields\n------\n\n### value\n\n protected volatile MessageLite value\n\nThe parsed value. When this is null and a caller needs access to the MessageLite value, then\n`delayedBytes` will be parsed lazily at that time.\n\nMethods\n-------\n\n### clear()\n\n public void clear()\n\nClears the value state of this instance.\n\nLazyField is not thread-safe for write access. Synchronizations are needed under read/write\nsituations.\n\n### containsDefaultInstance()\n\n public boolean containsDefaultInstance()\n\nDetermines whether this LazyFieldLite instance represents the default instance of this type.\n\n### ensureInitialized(MessageLite defaultInstance)\n\n protected void ensureInitialized(MessageLite defaultInstance)\n\nMight lazily parse the bytes that were previously passed in. Is thread-safe.\n\n### equals(Object o)\n\n public boolean equals(Object o)\n\n**Overrides** \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)\n\n### getSerializedSize()\n\n public int getSerializedSize()\n\nDue to the optional field can be duplicated at the end of serialized bytes, which will make the\nserialized size changed after LazyField parsed. Be careful when using this method.\n\n### getValue(MessageLite defaultInstance)\n\n public MessageLite getValue(MessageLite defaultInstance)\n\nReturns message instance. It may do some thread-safe delayed parsing of bytes.\n\n### hashCode()\n\n public int hashCode()\n\n**Overrides** \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)\n\n### merge(LazyFieldLite other)\n\n public void merge(LazyFieldLite other)\n\nMerges another instance's contents. In some cases may drop some extensions if both fields\ncontain data. If the other field has an `ExtensionRegistry` but this does not, then this\nfield will copy over that `ExtensionRegistry`.\n\nLazyField is not thread-safe for write access. Synchronizations are needed under read/write\nsituations.\n\n### mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)\n\n public void mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)\n\nMerges another instance's contents from a stream.\n\nLazyField is not thread-safe for write access. Synchronizations are needed under read/write\nsituations.\n\n### set(LazyFieldLite other)\n\n public void set(LazyFieldLite other)\n\nOverrides the contents of this LazyField.\n\nLazyField is not thread-safe for write access. Synchronizations are needed under read/write\nsituations.\n\n### setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry)\n\n public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry)\n\nSets this field with bytes to delay-parse.\n\n### setValue(MessageLite value)\n\n public MessageLite setValue(MessageLite value)\n\nSets the value of the instance and returns the old value without delay parsing anything.\n\nLazyField is not thread-safe for write access. Synchronizations are needed under read/write\nsituations.\n\n### toByteString()\n\n public ByteString toByteString()\n\nReturns a BytesString for this field in a thread-safe way."]]