├── Autentica.class ├── Autentica.java ├── Cliente.class ├── Cliente.java ├── MostraCliente.class ├── MostraCliente.java ├── Teste$1.class ├── Teste.class ├── Teste.java ├── TesteStream.class └── TesteStream.java /Autentica.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichelliBrito/java8/b77c31f93feffdc05b1e23e017d22dedd966bffa/Autentica.class -------------------------------------------------------------------------------- /Autentica.java: -------------------------------------------------------------------------------- 1 | @FunctionalInterface 2 | public interface Autentica{ 3 | public abstract boolean autenticaSenha(String senha); 4 | 5 | } 6 | -------------------------------------------------------------------------------- /Cliente.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichelliBrito/java8/b77c31f93feffdc05b1e23e017d22dedd966bffa/Cliente.class -------------------------------------------------------------------------------- /Cliente.java: -------------------------------------------------------------------------------- 1 | public class Cliente implements Autentica{ 2 | private String nome; 3 | private boolean status; 4 | private String senha; 5 | private int pontos; 6 | 7 | public Cliente(String nome, boolean status, String senha, int pontos){ 8 | this.nome = nome; 9 | this.status = status; 10 | this.senha = senha; 11 | this.pontos = pontos; 12 | } 13 | 14 | public String getNome(){ 15 | System.out.println(this.nome); 16 | return this.nome; 17 | } 18 | 19 | public boolean getStatus(){ 20 | return this.status; 21 | } 22 | 23 | public String getSenha(){ 24 | return this.senha; 25 | } 26 | 27 | public int getPontos(){ 28 | return this.pontos; 29 | } 30 | 31 | public boolean autenticaSenha(String senha) { 32 | if(this.senha != senha){ 33 | System.out.println("Não autenticado!"); 34 | return false; 35 | } 36 | System.out.println("Autenticado!"); 37 | return true; 38 | } 39 | 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /MostraCliente.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichelliBrito/java8/b77c31f93feffdc05b1e23e017d22dedd966bffa/MostraCliente.class -------------------------------------------------------------------------------- /MostraCliente.java: -------------------------------------------------------------------------------- 1 | import java.util.function.*; 2 | 3 | public class MostraCliente implements Consumer{ 4 | public void accept(Cliente c) { 5 | System.out.println(c.getNome()); 6 | System.out.println(c.getSenha()); 7 | } 8 | } -------------------------------------------------------------------------------- /Teste$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichelliBrito/java8/b77c31f93feffdc05b1e23e017d22dedd966bffa/Teste$1.class -------------------------------------------------------------------------------- /Teste.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichelliBrito/java8/b77c31f93feffdc05b1e23e017d22dedd966bffa/Teste.class -------------------------------------------------------------------------------- /Teste.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.util.function.*; 4 | 5 | 6 | public class Teste{ 7 | public static void main(String[] args){ 8 | Cliente c1 = new Cliente("michelli", true, "123"); 9 | Cliente c2 = new Cliente("bruno", true, "456"); 10 | c1.autenticaSenha("852"); 11 | 12 | 13 | List clientes = Arrays.asList(c1, c2); 14 | 15 | // MostraCliente mc = new MostraCliente(); 16 | // clientes.forEach(mc); 17 | 18 | // Consumer consumidor = new Consumer(){ //CLASSE ANÔNIMA 19 | // public void accept(Cliente c){ 20 | // System.out.println(c.getNome()); 21 | // } 22 | // }; 23 | //clientes.forEach(consumidor); 24 | 25 | //clientes.forEach(c -> System.out.println(c.getNome())); //EXPRESSÃO LAMBDA 26 | 27 | clientes.forEach(Cliente::getNome); //METHOD REFERENCE 28 | 29 | 30 | Cliente c3 = new Cliente("Ana", false, "333"); 31 | 32 | Consumer consumidor1 = Cliente::getNome; //METHOD REFERENCE 33 | consumidor1.accept(c3); 34 | 35 | Runnable r1 = c3::getNome; //METHOD REFERENCE 36 | r1.run(); 37 | 38 | 39 | 40 | Runnable r = () -> System.out.println("Olá mundo!"); //EXPRESSÃO LAMBDA 41 | new Thread(r).start(); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /TesteStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichelliBrito/java8/b77c31f93feffdc05b1e23e017d22dedd966bffa/TesteStream.class -------------------------------------------------------------------------------- /TesteStream.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.util.function.*; 4 | import java.util.stream.*; 5 | 6 | public class TesteStream{ 7 | 8 | public static void main(String[] args){ 9 | 10 | Cliente c1 = new Cliente("michelli", true, "123", 5); 11 | Cliente c2 = new Cliente("maria", true, "456", 10); 12 | Cliente c3 = new Cliente("josé", true, "789", 20); 13 | 14 | List clientes = Arrays.asList(c1, c2, c3); 15 | //clientes.forEach(c -> System.out.println(c.getPontos())); 16 | 17 | Set stream = clientes.stream().filter(c -> c.getPontos()>5).collect(Collectors.toSet()); 18 | 19 | //List pontosMaiorCinco = stream.collect(Collectors.toList()); 20 | 21 | stream.forEach(c -> System.out.println(c.getPontos())); 22 | 23 | } 24 | 25 | } --------------------------------------------------------------------------------