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

@NotNull and Optional parsed argument values #440

Closed
CubBossa opened this issue May 2, 2023 · 3 comments
Closed

@NotNull and Optional parsed argument values #440

CubBossa opened this issue May 2, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request implemented for next release This has been implemented in the current dev build for the next public release

Comments

@CubBossa
Copy link

CubBossa commented May 2, 2023

Description

Could we maybe have get(int) in our arguments with @NotNull and as replacement Optional getOptional(int)? In most cases the argument can't be null and if its supposed to potentially be, one could use the optional getter. An exception could be thrown in the get method if the object is expected to be notnull but is null

Expected code

Before:

@Nullable Object get(int index);

After:

@NotNull Object get(int index);
Optional<Object> getOptional(int index);

Extra details

No response

@CubBossa CubBossa added the enhancement New feature or request label May 2, 2023
@DerEchtePilz DerEchtePilz self-assigned this May 2, 2023
@DerEchtePilz
Copy link
Collaborator

I would not replace the @Nullable Object get(int index) with @NonNull Object get(int index) and throw an exception in the @NonNull annotated method because we initially implemented it like that and later decided to just let it return null.
Also the developer knows it can‘t be null if no argument is optional and could just suppress the warning.

However, I really like the idea of the Optional<Object> getOptional(int index) because this basically replaces all of the CommandArguments#getOrDefault methods because the Optional class implements it anyway.

If you or anyone else reading this has any more thoughts I‘d like hearing them!

DerEchtePilz added a commit that referenced this issue May 3, 2023
@DerEchtePilz
Copy link
Collaborator

@CubBossa I implemented a first implementation of this over here!

@DerEchtePilz DerEchtePilz added the implemented for next release This has been implemented in the current dev build for the next public release label May 4, 2023
@JorelAli
Copy link
Owner

Implemented in 9.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request implemented for next release This has been implemented in the current dev build for the next public release
Projects
Archived in project
Development

No branches or pull requests

3 participants