Skip to content

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

License

Notifications You must be signed in to change notification settings

brandonfl/throwable-optional

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages