Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param = foo.getSomthing1().getSomthig2().getSomthing3() ...
- if (foo != null && foo.getSomthing1() != null && ....) {
- param = foo.getSomthing1().getSomthig2().getSomthing3() ...
- }
- param = foo?.getSomthing1()?.getSomthig2()?.getSomthing3() ...
- public class TestClass{
- public Optional<TestClass> getSomthing1(){
- return Optional.of(this);
- }
- public Optional<TestClass> getSomthing2(){
- return Optional.of(this);
- }
- }
- TestClass test = new TestClass();
- test.getSomthing1().ifPresent(t -> t.getSomthing2());
- private Optional<String> get(First first) {
- return Optional.ofNullable(first.getSecond())
- .map(Second::getThird)
- .map(Third::getFourth)
- .map(Fourth::getString);
- }
- get(something).orElse("is null")
- Object fooMethod(Object fooObject) {
- if (fooObject == null)
- return null;
- else
- return fooMethod(fooObject.getSomething());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement