Skip to content

Added method to convert Object to String that support null values.#889

Closed
EACUAMBA wants to merge 4 commits intoapache:masterfrom
EACUAMBA:master
Closed

Added method to convert Object to String that support null values.#889
EACUAMBA wants to merge 4 commits intoapache:masterfrom
EACUAMBA:master

Conversation

@EACUAMBA
Copy link
Copy Markdown

@EACUAMBA EACUAMBA commented May 1, 2022

I added a method to help people convert any object to String or return an empty String.

I added this methods because I was facing a problem with convert Wrap classes like Integer, Double to String.
I needed something to return empty string or a default value.

This is my contribute.

if(object == null)
return defaultString(nullDefault);

return Objects.toString(object);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @EACUAMBA ,

I think instead of this new method, users could just use the Java 8+ Objects.toString(Object o, String nullDefault) - https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#toString-java.lang.Object-java.lang.String-

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @kinow,

You are right, the toString method in Objects can work too. Thanks.

@EACUAMBA EACUAMBA closed this May 1, 2022
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.

2 participants