Skip to content

simplify boring null judgement. e.g: if (a != null && a.getB() !=null && a.getB().getC() != null && ...)

Notifications You must be signed in to change notification settings

elvis9xu163/gets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gets

简化烦人的null值判断操作
simplify boring null judgement. e.g: if (a != null && a.getB() !=null && a.getB().getC() != null && ...)
Example:

A a = null;

// ... some operations

// traditional way
if (a != null && a.getB() != null && a.getB().getC() != null
		&& a.getB().getC().getD() != null && a.getB().getC().getD().getList() != null) {
	for (Object item : a.getB().getC().getD().getList()) {
		// ... do some business
	}
}

// use Gets way
if (Gets.isNotNull(Gets.wrap(a, A.class).getB().getC().getD().getList())) {
	// ... do 'for' business
}

// or use Gets as
if (Gets.get(Gets.wrap(a, A.class).getB().getC().getD().getList()) != null) {
	// ... do 'for' business
}

// some other use
String key = Gets.get(Gets.wrap(a, A.class).getB().getC().getD().getKey(), "NO_KEY");
System.out.println(key); // key = "NO_KEY";

About

simplify boring null judgement. e.g: if (a != null && a.getB() !=null && a.getB().getC() != null && ...)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages