Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- System.out.println("Nome: " + pessoa.getNome());
- if (pessoa!=null) {
- System.out.println("Nome: " + pessoa.getNome());
- }
- Optional<Integer> possible = Optional.of(5);
- possible.isPresent(); // retorna true
- possible.get(); // retorna 5
- possible.or(0); // retorna o valor se existir, se não houver nada, retorna 0
- assert <condição>
- assert <condição> : <objeto>
- public Pessoa obterPessoa(int id) {
- Pessoa resultado = null;
- if (id > 50) {
- resultado = datasource.getPessoa(id);
- } else {
- resultado = new Pessoa(id);
- }
- assert resultado != null : "pessoa nula no método obterPessoa()";
- return resultado;
- }
- public interface Animal {
- public void makeSound();
- }
- public class Dog implements Animal {
- public void makeSound() {
- System.out.println("woof!");
- }
- }
- public class NullAnimal implements Animal {
- public void makeSound() {
- }
- }
Add Comment
Please, Sign In to add comment