Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arojunior/java-null-utils
Just an experiment to write less code in Java
https://github.com/arojunior/java-null-utils
java
Last synced: 16 days ago
JSON representation
Just an experiment to write less code in Java
- Host: GitHub
- URL: https://github.com/arojunior/java-null-utils
- Owner: arojunior
- Created: 2018-04-17T22:41:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-17T22:43:52.000Z (over 6 years ago)
- Last Synced: 2024-11-07T13:53:22.086Z (2 months ago)
- Topics: java
- Language: Java
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Java-null-utils
Just an experiment to use with Java somenthing like the `get` method from Javascript's `lodash`
```java
class Country {
private String name;public String getName() {
return name;
}public void setName(final String name) {
this.name = name;
}
}class Person {
private String name;
private Country country;public String getName() {
return name;
}public void setName(final String name) {
this.name = name;
}public Country getCountry() {
return country;
}public void setCountry(final Country country) {
this.country = country;
}
}
```What if you need to access the country's name from Person object to pass as argument to a method?
You probably will do something like this to prevent NullPointerException
```java
if (person.getCountry() != null && person.getCountry().getName() != null) {
myMethod(person.getCountry().getName());
}
```With this checking you can write less code:
```java
if (NullUtils.isNotNull(person, "getCountry.getName")) {
myMethod(person.getCountry().getName());
}
```Take a look at test file.