Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java: Use Optional<T> to indicate optional values #50

Merged
merged 2 commits into from Jan 5, 2022

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Jan 4, 2022

Permanently avoid the problems from cucumber/cucumber-jvm#2454

@mpkorstanje
Copy link
Contributor Author

@aslakhellesoy in Javascript buildNumber is not optional:

https://github.com/cucumber/ci-environment/blob/main/javascript/src/types.ts#L4

However the value is evaluated from an expression and may be null. Which one is correct?

Copy link
Contributor

@aslakhellesoy aslakhellesoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!! This will teach me to use Optional :-)

@aslakhellesoy
Copy link
Contributor

@aslakhellesoy in Javascript buildNumber is not optional:

https://github.com/cucumber/ci-environment/blob/main/javascript/src/types.ts#L4

However the value is evaluated from an expression and may be null. Which one is correct?

Good catch. I think we should allow null for that field. Working on a fix...

@aslakhellesoy
Copy link
Contributor

@aslakhellesoy in Javascript buildNumber is not optional:
https://github.com/cucumber/ci-environment/blob/main/javascript/src/types.ts#L4
However the value is evaluated from an expression and may be null. Which one is correct?

Good catch. I think we should allow null for that field. Working on a fix...

Fixed in #51

@mpkorstanje
Copy link
Contributor Author

Great!! This will teach me to use Optional :-)

It's relatively simple. Only ever use it as a return type. Don't use it as an argument. When used as a return type, never return null.

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Optional.html

@mpkorstanje mpkorstanje merged commit e7e86e6 into main Jan 5, 2022
@mpkorstanje mpkorstanje deleted the use-optional-values branch January 5, 2022 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants