Skip to content

Latest commit

 

History

History
73 lines (58 loc) · 2.45 KB

README.md

File metadata and controls

73 lines (58 loc) · 2.45 KB


Throwable Optional

Java utility class that enables the possibility to use the Optional with functions that can throw exceptions

release maven-central Java CI CodeQL Sonar gate licence

How to useVariablesLicence

How to use

Installation

<dependency>
  <groupId>xyz.brandonfl</groupId>
  <artifactId>throwable-optional</artifactId>
  <version>VERSION</version>
</dependency>
mvn install

More informations : https://github.com/brandonfl/throwable-optional/packages/

Examples

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

Licence

Project under MIT licence