-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reflection of methods and parameters
- Loading branch information
1 parent
fd483e9
commit 25a4826
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Parameter; | ||
|
||
class Produto { | ||
private String nome; | ||
private Double preco; | ||
|
||
public Produto(String nome, Double preco) { | ||
this.nome = nome; | ||
this.preco = preco; | ||
} | ||
|
||
public String getNome() { | ||
return nome; | ||
} | ||
|
||
public void setNome(String nome) { | ||
this.nome = nome; | ||
} | ||
|
||
public Double getPreco() { | ||
return preco; | ||
} | ||
|
||
public void setPreco(Double preco) { | ||
this.preco = preco; | ||
} | ||
} | ||
|
||
public class ReflexaoExemplo { | ||
|
||
public static void main(String[] args) { | ||
|
||
//Instância da classe Produto | ||
Produto p = new Produto("Geladeira", 3000.00); | ||
|
||
//Instância da classe Class | ||
Class<? extends Produto> cl = p.getClass(); | ||
|
||
//Todos os métodos declarados na classe Produto | ||
Method[] method = cl.getDeclaredMethods(); | ||
|
||
for(Method m : method) { | ||
System.out.println(m.getName()); | ||
|
||
//Parâmetros do método | ||
Parameter[] parameter = m.getParameters(); | ||
|
||
for(Parameter pr : parameter) { | ||
System.out.println(pr); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} |