Java utility class that enables the possibility to use the Optional with functions that can throw exceptions
How to use • Variables • Licence
<dependency>
<groupId>xyz.brandonfl</groupId>
<artifactId>throwable-optional</artifactId>
<version>VERSION</version>
</dependency>
mvn install
More informations : https://github.com/brandonfl/throwable-optional/packages/
public static void main(String[] args){
long valueWithTest = ThrowableOptional
.of(() -> Long.parseLong("test"))
.orElse(0L);
long valueWith1 = ThrowableOptional
.of(() -> Long.parseLong("1"))
.orElse(0L);
long valueWithFunction = ThrowableOptional
.of(Long::parseLong, "1")
.orElse(0L);
System.out.println(valueWithTest);
System.out.println(valueWith1);
System.out.println(valueWithFunction);
}
That will return without exceptions :
0
1
1
Project under MIT licence