Last active
March 21, 2017 01:09
-
-
Save jeffersontpadua/d360ccef3494d24d3856d1e1f0ab68bf to your computer and use it in GitHub Desktop.
Method overloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
public class Pessoa { | |
public List<Pensamento> pensar(boolean tempoLivre) { | |
if(tempoLivre) { | |
return Arrays.asList(new Pensamento("Livros"), new Pensamento("Estudos")); | |
}else { | |
return Arrays.asList(new Pensamento("Programação"), new Pensamento("Java")); | |
} | |
} | |
public List<Pensamento> pensar(boolean estaComFome, boolean tempoLive) { | |
if (estaComFome) { | |
return Arrays.asList(new Pensamento("Comida"), new Pensamento("Comida"), new Pensamento("Comida")); | |
} else { | |
return pensar(tempoLive); | |
} | |
} | |
public List<Pensamento> pensar(boolean estaApaixonado, boolean estaComFome, boolean tempoLivre) { | |
if(estaApaixonado) { | |
return Arrays.asList(new Pensamento("\"Aquela\" pessoa"), | |
new Pensamento("\"Aquela\" pessoa"), new Pensamento("\"Aquela\" pessoa")); | |
}else if(estaComFome) { | |
return pensar(estaComFome, tempoLivre); | |
}else { | |
return pensar(tempoLivre); | |
} | |
} | |
private class Pensamento { | |
private String descricao; | |
private Pensamento(String descricao) { | |
this.descricao = descricao; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TratandoParametros { | |
public static void main(String[] args) { | |
Pessoa pessoa = new Pessoa("Jefferson"); | |
Integer numero = 5; | |
modificarObjeto(pessoa, "Jefferson T Padua"); | |
modificarTipoPrimitivo(numero, 10); | |
System.out.println(pessoa.getNome());//Jefferson T Padua | |
System.out.println(numero); //5 | |
} | |
public static void modificarObjeto(Pessoa pessoa, String nome) { | |
pessoa.setNome(nome); | |
} | |
public static void modificarTipoPrimitivo(Integer numero, int outroNumero) { | |
numero = numero + outroNumero; | |
} | |
public static class Pessoa { | |
private String nome; | |
public Pessoa(String nome) { | |
this.nome = nome; | |
} | |
public String getNome() { | |
return nome; | |
} | |
public void setNome(String nome) { | |
this.nome = nome; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment