Guest User

Untitled

a guest
Oct 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. System.out.println("Nome: " + pessoa.getNome());
  2.  
  3. if (pessoa!=null) {
  4. System.out.println("Nome: " + pessoa.getNome());
  5. }
  6.  
  7. Optional<Integer> possible = Optional.of(5);
  8. possible.isPresent(); // retorna true
  9. possible.get(); // retorna 5
  10.  
  11. possible.or(0); // retorna o valor se existir, se não houver nada, retorna 0
  12.  
  13. assert <condição>
  14.  
  15. assert <condição> : <objeto>
  16.  
  17. public Pessoa obterPessoa(int id) {
  18. Pessoa resultado = null;
  19. if (id > 50) {
  20. resultado = datasource.getPessoa(id);
  21. } else {
  22. resultado = new Pessoa(id);
  23. }
  24. assert resultado != null : "pessoa nula no método obterPessoa()";
  25.  
  26. return resultado;
  27. }
  28.  
  29. public interface Animal {
  30. public void makeSound();
  31. }
  32.  
  33. public class Dog implements Animal {
  34. public void makeSound() {
  35. System.out.println("woof!");
  36. }
  37. }
  38.  
  39. public class NullAnimal implements Animal {
  40. public void makeSound() {
  41. }
  42. }
Add Comment
Please, Sign In to add comment