Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Optional;
- class Main {
- int a;
- int b;
- public static void main(String[] args) {
- Main objMain = new Main();
- Arbol objArbol = new Arbol(
- null,
- new Arbol(null,null,4),
- 6
- );
- Optional.ofNullable(objArbol.izq).ifPresent(x -> objMain.a = x.value);
- Optional.ofNullable(objArbol.der).ifPresent(x -> objMain.b = x.value);
- System.out.println("a " + objMain.a + " b " + objMain.b);
- }
- }
- class Arbol {
- Arbol izq;
- Arbol der;
- int value;
- Arbol (Arbol izq, Arbol der, int value) {
- this.izq = izq;
- this.der = der;
- this.value = value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement