当前位置:网站首页>Optional consistency
Optional consistency
2022-07-24 05:18:00 【Hua Weiyun】
Catalog
- 1. java.util.Optional
- 1.1 public static Optional empty()
- 1.2 public static Optional of(T value)
- 1.3 public static Optional ofNullable(T value)
- 1.4 public T get()
- 1.5 public boolean isPresent()
- 1.6 public boolean isEmpty()
- 1.7 public void ifPresent(Consumer<? super T> action)
- 1.8 public void ifPresentOrElse(Consumer<? super T> action, Runnable emptyAction)
- 1.9 public Optional filter(Predicate<? super T> predicate)
- 1.10 public Optional map(Function<? super T, ? extends U> mapper)
- 1.11 public Optional flatMap(Function<? super T, ? extends Optional<? extends U>> mapper)
- 1.12 public Optional or(Supplier<? extends Optional<? extends T>> supplier)
- 1.13 public Stream stream()
- 1.14 public T orElse(T other)
- 1.15 public T orElseGet(Supplier<? extends T> supplier)
- 1.16 public T orElseThrow()
- 1.17 public T orElseThrow(Supplier<? extends X> exceptionSupplier) throws
- 1.18 public boolean equals(Object obj)
- 1.19 public int hashCode()
- 1.20 public String toString()
1. java.util.Optional
Optional An object is a wrapper object , As a safer way , Used instead of type T References to , It is used to solve the problems caused by the abnormal null index .
1.1 public static Optional empty()
Generate an empty Optional.
1.2 public static Optional of(T value)
Generate a with a given value Optional, If value by null, It will be thrown out. NullPointerException.
1.3 public static Optional ofNullable(T value)
Generate a with a given value Optional, If value by null, Will produce an empty Optional.
1.4 public T get()
Get current Optional Value , If at present Optional It's empty , Throw out NoSuchElementException.
1.5 public boolean isPresent()
If at present Optional Not empty , Then return to false.
1.6 public boolean isEmpty()
If at present Optional It's empty , Then return to true.
1.7 public void ifPresent(Consumer<? super T> action)
If at present Optional Not empty , Then execute the specified Consumer.
1.8 public void ifPresentOrElse(Consumer<? super T> action, Runnable emptyAction)
If at present Optional Not empty , Then execute the specified Consumer, Otherwise, execute the specified Runable.
1.9 public Optional filter(Predicate<? super T> predicate)
If at present Optional It's empty , Returns an empty Optional, Otherwise, execute the specified Predicate, If the execution result is true, Then return to the current Optional, Otherwise, it returns empty Optional.
1.10 public Optional map(Function<? super T, ? extends U> mapper)
Return to the current Optional The value of is passed to the specified Function And package the results into Optional, If at present Optional Is empty or Function Execution result is empty , It returns null Optional.
1.11 public Optional flatMap(Function<? super T, ? extends Optional<? extends U>> mapper)
Return to the current Optional The value of is passed to the specified Function After the results of the , If at present Optional Is empty or Function Execution result is empty , It returns null Optional, This method is similar to the above map The difference between the method and map Methods will Function The returned results are automatically wrapped into Optional type , and flatMap Methodical Function The returned result must be Optional type ,flatMap The return result of and Function The result remains the same .
1.12 public Optional or(Supplier<? extends Optional<? extends T>> supplier)
If at present Optional Not empty , Then return to the current Optional, Otherwise return to Supplier The result of execution , The result must be Optional type , if Supplier The result after execution is empty , Throw out NullPointerException.
1.13 public Stream stream()
If at present Optional It's empty , It returns null Stream, Otherwise, the return contains the current Optional The value of the Stream.
1.14 public T orElse(T other)
If at present Optional Not empty , Returns the current Optional Value , Otherwise, the specified object is returned other.
1.15 public T orElseGet(Supplier<? extends T> supplier)
If at present Optional Not empty , Returns the current Optional Value , Otherwise, return the specified Supplier Generated objects .
1.16 public T orElseThrow()
If at present Optional Not empty , Returns the current Optional Value , Otherwise throw NoSuchElementException.
1.17 public T orElseThrow(Supplier<? extends X> exceptionSupplier) throws
If at present Optional Not empty , Returns the current Optional Value , Otherwise, the specified Supplier Generated exception .
1.18 public boolean equals(Object obj)
A little .
1.19 public int hashCode()
A little .
1.20 public String toString()
A little .
边栏推荐
- This article takes you to understand C string functions and memory functions in simple terms
- PXE efficient batch network installation
- PPPoE gateway simulation environment setup
- Kingbase v8r6 cluster installation and deployment case - script online one click expansion
- Teach you how to weld CAD design board bottom (for beginners) graphic tutorial
- OSS文件上传
- ssm的整合
- The network NN can calculate the NTCP provided by the host system
- jdbc封装一个父类减少代码重复
- [database connection] - excerpt from training
猜你喜欢

线程的介绍

Blue Bridge Cup 31 day sprint 21 day (C language)

线程

MGRE and OSPF comprehensive experiment

Image painting for irregular holes using partial revolutions paper notes

Wang Qing, director of cloud infrastructure software research and development of Intel (China): Intel's technology development and prospects in cloud native
![[advanced mathematics] the difference between differentiable and differentiable functions](/img/32/ead52f0d451e3c07a22c7a107fc8b9.jpg)
[advanced mathematics] the difference between differentiable and differentiable functions

HCIA NAT experiment

熊市抄底指南
![Rlib learning - [4] - algorithmconfig detailed introduction [pytoch version]](/img/1e/95078ad64a17686463547e8ba87cb1.png)
Rlib learning - [4] - algorithmconfig detailed introduction [pytoch version]
随机推荐
Token of space renewable energy
Blue Bridge Cup 31 day sprint 21 day (C language)
Pointer learning diary (II)
SSH service
Performance test process
I'm interested in reading efficient reading - the most cost-effective self investment
XML schema
Memorandum 2022
frp内网穿透服务使用
浅谈不可转让的声誉积分NFT SBTs面临的困境
Jetson设备 faild to download repository information使用小技巧记录
Hotel IPTV digital TV system solution
C primer plus learning notes - 5. Pointer
DHCP principle and configuration
Globally and locally consistent image completion paper notes
。 Single type digital sensing is an application 0 Up address is at the factory
Using a* heuristic search to solve maze routing problem
[Huang ah code] Introduction to MySQL - 3. I use select *, and the boss directly rushed me home by train, but I still bought a station ticket
Image to image translation with conditional advantageous networks paper notes
[advanced mathematics] the difference between differentiable and differentiable functions