2
I have an arraylist with three positions. I added to the array, objects like Manager, Seller and Technician, respectively. Using the getClass
, would like to know how do I know which object is in each vector position.
I did it this way, but it didn’t make any mistakes and it didn’t call my methods.
public static void mostrarSalarioFuncionario() {
ArrayList<Funcionario> listaFunc = new ArrayList<Funcionario>();
listaFunc.add(ge);
listaFunc.add(te);
listaFunc.add(ve);
System.out.println("CALCULO SALARIO DO FUNCIONARIO");
for (int i = 0; i < listaFunc.size(); i++) {
if (listaFunc.get(i).getClass().equals(ge) {
System.out.println("Classe...:Gerente");
System.out.println("Salário..:"+ge.calcularSalario());;
}
else if(listaFunc.get(i).getClass().equals(ve)) {
System.out.println("Classe...:Vendedor");
System.out.println("Salário..:"+ve.calcularSalario());;
}
else if (listaFunc.get(i).getClass().equals(te)) {
System.out.println("Classe...:Técnico");
System.out.println("Salário..:"+te.calcularSalario());
}
}
Use
instance of
instead ofgetClass
. I’d even show you an example, but this bit of code doesn’t make sense with the doubt of the question.– user28595
reformulated the question could exemplify with instance of?
– Diogo Lopes
What is you and see?
– user28595
an object of the type Seller and the type Tecnico
– Diogo Lopes