Uses of Class
java.util.Optional
Package
Description
Provides classes that are fundamental to the design of the Java
programming language.
Provides classfile parsing, generation, and transformation library.
Provides interfaces describing classfile attributes for the
java.lang.classfile
PREVIEW library.Provides specific components, transformations, and tools built on top of the
java.lang.classfile
PREVIEW library.Provides interfaces describing code instructions for the
java.lang.classfile
PREVIEW library.Classes and interfaces to represent nominal descriptors for run-time
entities such as classes or method handles, and classfile entities such as
constant pool entries or
invokedynamic
call sites.Provides low-level access to memory and functions outside the Java runtime.
The
java.lang.invoke
package provides low-level primitives for interacting
with the Java Virtual Machine.Classes to support module descriptors and creating configurations of modules
by means of resolution and service binding.
Provides the classes for implementing networking applications.
HTTP Client and WebSocket APIs
Provides interfaces for generating RSA (Rivest, Shamir and
Adleman AsymmetricCipher algorithm)
keys as defined in the RSA Laboratory Technical Note
PKCS#1, and DSA (Digital Signature
Algorithm) keys as defined in NIST's FIPS-186.
Provides classes and interfaces for key specifications and algorithm
parameter specifications.
Contains the collections framework, some internationalization support classes,
a service loader, properties, random number generation, string parsing
and scanning classes, base64 encoding and decoding, a bit array, and
several miscellaneous utility classes.
Utility classes commonly useful in concurrent programming.
Service provider classes for the classes in the java.util package.
Classes to support functional-style operations on streams of elements, such
as map-reduce transformations on collections.
Provides the Service Provider Interface for DNS lookups when
performing LDAP operations.
Provides classes for the secure socket package.
Defines the Service Provider Interface for pluggable JShell execution engines.
-
Uses of Optional in java.lang
Modifier and TypeMethodDescriptionProcessHandle.Info.arguments()
Returns an array of Strings of the arguments of the process.Runtime.Version.build()
Returns the build number.ProcessHandle.Info.command()
Returns the executable pathname of the process.ProcessHandle.Info.commandLine()
Returns the command line of the process.Boolean.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance.Byte.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance.Character.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance.Class.describeConstable()
Returns a nominal descriptor for this instance, if one can be constructed, or an emptyOptional
if one cannot be.Double.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance, which is the instance itself.final Optional
<Enum.EnumDesc<E>> Enum.describeConstable()
Returns an enum descriptorEnumDesc
for this instance, if one can be constructed, or an emptyOptional
if one cannot be.Float.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance, which is the instance itself.Integer.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance, which is the instance itself.Long.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance, which is the instance itself.Short.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance.String.describeConstable()
Returns anOptional
containing the nominal descriptor for this instance, which is the instance itself.ModuleLayer.findModule
(String name) Returns the module with the given name in this layer, or if not in this layer, the parent layers.static Optional
<ProcessHandle> ProcessHandle.of
(long pid) Returns anOptional<ProcessHandle>
for an existing native process.Runtime.Version.optional()
Returns optional additional identifying build information.ProcessHandle.parent()
Returns anOptional<ProcessHandle>
for the parent process.Runtime.Version.pre()
Returns the optional pre-release information.ProcessHandle.Info.startInstant()
Returns the start time of the process.ProcessHandle.Info.totalCpuDuration()
Returns the total cputime accumulated of the process.ProcessHandle.Info.user()
Return the user of the process. -
Uses of Optional in java.lang.classfilePREVIEW
Modifier and TypeMethodDescriptionSignature.TypeParam.classBound()
Returns the class bound of the type parameter.MethodModel.code()
Returns the body of this method, if there is one.AttributedElement.findAttribute
(AttributeMapperPREVIEW<T> attr) Finds an attribute by name.Signature.ClassTypeSig.outerType()
Returns the signature of the outer type, if any.CodeModel.parent()
Returns the enclosing method, if known.FieldModel.parent()
Returns the class model this field is a member of, if known.MethodModel.parent()
Returns the class model this method is a member of, if known.ClassModel.superclass()
Returns the superclass of this class, if there is one.ClassReader.superclassEntry()
Returns the constant pool entry describing the name of the superclass, if any.Modifier and TypeMethodDescriptiondefault CodeBuilderPREVIEW
CodeBuilder.exceptionCatch
(LabelPREVIEW start, LabelPREVIEW end, LabelPREVIEW handler, Optional<ClassEntryPREVIEW> catchType) Declare an exception table entrystatic Signature.TypeParamPREVIEW
Signature.TypeParam.of
(String identifier, Optional<Signature.RefTypeSigPREVIEW> classBound, Signature.RefTypeSigPREVIEW... interfaceBounds) Returns a signature for a type parameter. -
Uses of Optional in java.lang.classfile.attributePREVIEW
Modifier and TypeMethodDescriptionEnclosingMethodAttribute.enclosingMethod()
Returns the name and type of the enclosing method, if the class is immediately enclosed by a method or constructor.EnclosingMethodAttribute.enclosingMethodName()
Returns the name of the enclosing method, if the class is immediately enclosed by a method or constructor.EnclosingMethodAttribute.enclosingMethodType()
Returns the type of the enclosing method, if the class is immediately enclosed by a method or constructor.default Optional
<MethodTypeDesc> EnclosingMethodAttribute.enclosingMethodTypeSymbol()
Returns the type of the enclosing method, if the class is immediately enclosed by a method or constructor.InnerClassInfo.innerName()
Returns the simple name of this class, or empty if this class is anonymous.ModuleAttribute.moduleVersion()
Returns the version of the module, if present.MethodParameterInfo.name()
The name of the method parameter, if there is one.InnerClassInfo.outerClass()
Returns the class or interface of which this class is a member, if it is a member of a class or interface.ModuleRequireInfo.requiresVersion()
Returns the required version of the required module, if present.Modifier and TypeMethodDescriptionEnclosingMethodAttribute.of
(ClassEntryPREVIEW className, Optional<NameAndTypeEntryPREVIEW> method) Returns anEnclosingMethod
attribute.EnclosingMethodAttribute.of
(ClassDesc className, Optional<String> methodName, Optional<MethodTypeDesc> methodType) Returns anEnclosingMethod
attribute.static InnerClassInfoPREVIEW
InnerClassInfo.of
(ClassEntryPREVIEW innerClass, Optional<ClassEntryPREVIEW> outerClass, Optional<Utf8EntryPREVIEW> innerName, int flags) Returns an inner class description.static InnerClassInfoPREVIEW
InnerClassInfo.of
(ClassDesc innerClass, Optional<ClassDesc> outerClass, Optional<String> innerName, int flags) Returns an inner class description.static InnerClassInfoPREVIEW
InnerClassInfo.of
(ClassDesc innerClass, Optional<ClassDesc> outerClass, Optional<String> innerName, AccessFlag... flags) Returns an inner class description.static MethodParameterInfoPREVIEW
Returns a method parameter description.static MethodParameterInfoPREVIEW
MethodParameterInfo.of
(Optional<String> name, AccessFlag... flags) Returns a method parameter description.static MethodParameterInfoPREVIEW
MethodParameterInfo.ofParameter
(Optional<String> name, int flags) Returns a method parameter description. -
Uses of Optional in java.lang.classfile.componentsPREVIEW
Modifier and TypeMethodDescriptionCodeStackTracker.maxStackSize()
Returns tracked max stack size.CodeStackTracker.stack()
Returns Collection of TypeKind representing current stack. -
Uses of Optional in java.lang.classfile.instructionPREVIEW
Modifier and TypeMethodDescriptionExceptionCatch.catchType()
Returns the type of the exception to catch, or empty if this handler is unconditional. -
Uses of Optional in java.lang.constant
-
Uses of Optional in java.lang.foreign
Modifier and TypeMethodDescriptionMemorySegment.asOverlappingSlice
(MemorySegment other) Returns a slice of this segment that is the overlap between this and the provided segment.Returns the address of the symbol with the given name.MemorySegment.heapBase()
Returns the Java object stored in the on-heap region of memory backing this memory segment, if any.MemoryLayout.name()
Returns the name (if any) associated with this layout.FunctionDescriptor.returnLayout()
Returns the return layout (if any) of this function descriptor.AddressLayout.targetLayout()
Returns the target layout associated with this address layout (if any). -
Uses of Optional in java.lang.invoke
Modifier and TypeMethodDescriptionMethodHandle.describeConstable()
Return a nominal descriptor for this instance, if one can be constructed, or an emptyOptional
if one cannot be.MethodType.describeConstable()
Returns a nominal descriptor for this instance, if one can be constructed, or an emptyOptional
if one cannot be.VarHandle.describeConstable()
Return a nominal descriptor for this instance, if one can be constructed, or an emptyOptional
if one cannot be. -
Uses of Optional in java.lang.module
Modifier and TypeMethodDescriptionModuleDescriptor.Requires.compiledVersion()
Returns the version of the module if recorded at compile-time.Finds a reference to a module of a given name.Finds a resource, returning a URI to the resource in the module.Configuration.findModule
(String name) Finds a resolved module in this configuration, or if not in this configuration, the parent configurations.ModuleReference.location()
Returns the location of this module's content, if known.ModuleDescriptor.mainClass()
Returns the module main class.default Optional
<InputStream> Opens a resource, returning an input stream to read the resource in the module.ModuleDescriptor.Requires.rawCompiledVersion()
Returns the string with the possibly-unparseable version of the module if recorded at compile-time.ModuleDescriptor.rawVersion()
Returns the string with the possibly-unparseable version of the module.default Optional
<ByteBuffer> Reads a resource, returning a byte buffer with the contents of the resource.ModuleDescriptor.version()
Returns the module version. -
Uses of Optional in java.net
Modifier and TypeMethodDescriptionSecureCacheResponse.getSSLSession()
Returns anOptional
containing theSSLSession
in use on the original connection that retrieved the network resource. -
Uses of Optional in java.net.http
Modifier and TypeMethodDescriptionabstract Optional
<Authenticator> HttpClient.authenticator()
Returns anOptional
containing theAuthenticator
set on this client.abstract Optional
<HttpRequest.BodyPublisher> HttpRequest.bodyPublisher()
Returns anOptional
containing theHttpRequest.BodyPublisher
set on this request.HttpClient.connectTimeout()
Returns anOptional
containing the connect timeout duration for this client.abstract Optional
<CookieHandler> HttpClient.cookieHandler()
Returns anOptional
containing this client'sCookieHandler
.HttpClient.executor()
Returns anOptional
containing this client'sExecutor
.HttpHeaders.firstValue
(String name) Returns anOptional
containing the first header string value of the given named (and possibly multi-valued) header.HttpResponse.previousResponse()
Returns anOptional
containing the previous intermediate response if one was received.abstract Optional
<ProxySelector> HttpClient.proxy()
Returns anOptional
containing theProxySelector
supplied to this client.HttpResponse.sslSession()
Returns anOptional
containing theSSLSession
in effect for this response.HttpRequest.timeout()
Returns anOptional
containing this request's timeout duration.abstract Optional
<HttpClient.Version> HttpRequest.version()
Returns anOptional
containing the HTTP protocol version that will be requested for thisHttpRequest
.Modifier and TypeMethodDescriptionstatic HttpResponse.BodyHandler
<Void> HttpResponse.BodyHandlers.ofByteArrayConsumer
(Consumer<Optional<byte[]>> consumer) Returns aBodyHandler<Void>
that returns aBodySubscriber
<Void>
obtained fromBodySubscribers.ofByteArrayConsumer(Consumer)
.static HttpResponse.BodySubscriber
<Void> HttpResponse.BodySubscribers.ofByteArrayConsumer
(Consumer<Optional<byte[]>> consumer) Returns aBodySubscriber
which provides the incoming body data to the provided Consumer ofOptional<byte[]>
. -
Uses of Optional in java.security.interfaces
-
Uses of Optional in java.security.spec
Modifier and TypeMethodDescriptionOptional
<byte[]> EdDSAParameterSpec.getContext()
Get the context that the signature will use. -
Uses of Optional in java.util
Modifier and TypeMethodDescriptionstatic <T> Optional
<T> Optional.empty()
Returns an emptyOptional
instance.If a value is present, and the value matches the given predicate, returns anOptional
describing the value, otherwise returns an emptyOptional
.ServiceLoader.findFirst()
Load the first available service provider of this loader's service.<U> Optional
<U> If a value is present, returns the result of applying the givenOptional
-bearing mapping function to the value, otherwise returns an emptyOptional
.<U> Optional
<U> If a value is present, returns anOptional
describing (as if byofNullable(T)
) the result of applying the given mapping function to the value, otherwise returns an emptyOptional
.static <T> Optional
<T> Optional.of
(T value) Returns anOptional
describing the given non-null
value.static <T> Optional
<T> Optional.ofNullable
(T value) Returns anOptional
describing the given value, if non-null
, otherwise returns an emptyOptional
.If a value is present, returns anOptional
describing the value, otherwise returns anOptional
produced by the supplying function.Modifier and TypeMethodDescription<U> Optional
<U> If a value is present, returns the result of applying the givenOptional
-bearing mapping function to the value, otherwise returns an emptyOptional
.If a value is present, returns anOptional
describing the value, otherwise returns anOptional
produced by the supplying function. -
Uses of Optional in java.util.concurrent
-
Uses of Optional in java.util.spi
Modifier and TypeMethodDescriptionToolProvider.description()
Returns a short description of the tool, or an emptyOptional
if no description is available.static Optional
<ToolProvider> Returns the first instance of aToolProvider
with the given name, as loaded byServiceLoader
using the system class loader. -
Uses of Optional in java.util.stream
Modifier and TypeMethodDescriptionStream.findAny()
Returns anOptional
describing some element of the stream, or an emptyOptional
if the stream is empty.Stream.findFirst()
Returns anOptional
describing the first element of this stream, or an emptyOptional
if the stream is empty.Stream.max
(Comparator<? super T> comparator) Returns the maximum element of this stream according to the providedComparator
.Stream.min
(Comparator<? super T> comparator) Returns the minimum element of this stream according to the providedComparator
.Stream.reduce
(BinaryOperator<T> accumulator) Performs a reduction on the elements of this stream, using an associative accumulation function, and returns anOptional
describing the reduced value, if any.Modifier and TypeMethodDescriptionCollectors.maxBy
(Comparator<? super T> comparator) Returns aCollector
that produces the maximal element according to a givenComparator
, described as anOptional<T>
.Collectors.minBy
(Comparator<? super T> comparator) Returns aCollector
that produces the minimal element according to a givenComparator
, described as anOptional<T>
.Collectors.reducing
(BinaryOperator<T> op) Returns aCollector
which performs a reduction of its input elements under a specifiedBinaryOperator
. -
Uses of Optional in javax.naming.ldap.spi
Modifier and TypeMethodDescriptionabstract Optional
<LdapDnsProviderResult> LdapDnsProvider.lookupEndpoints
(String url, Map<?, ?> env) Lookup the endpoints and domain name for the givenContext
provider URL
and environment. -
Uses of Optional in javax.net.ssl
Modifier and TypeMethodDescriptionHttpsURLConnection.getSSLSession()
Returns anOptional
containing theSSLSession
in use on this connection. -
Uses of Optional in jdk.jshell.spi
Modifier and TypeMethodDescriptiondefault Optional
<JShellConsole> ExecutionEnv.console()
Returns theJShellConsole
that should be used by the execution engine, ornull
if none.