Differences between using typecast and wrapper class?

0

Hello, the activity proposal would show how many years the user would have, I wrote my code first so I could compare it with the teacher, it turns out that my first line was much smaller than the teacher.

This is my code:

int an = (int) txtAN.getValue();    // an (ano de nascimento), pega o valor de um spinner
int ran = 2017 - an;    // ran (resultado do ano de nascimento)
lblIdade.setText(Integer.toString(ran));    // mostra no label o valor recebido

This is the teacher's:

int an = Integer.parseInt(txtAN.getValue().toString());
int id = 2017 - an;
lblIdade.setText(Inteer.toString(id));
  • What are the pros and cons of using typecast (as in my case), or use wrapper class (as in the case of the teacher)?
  • Which method is "right" or "wrong"? Why?
  • Note: This is a project using Swing.

        
    asked by anonymous 22.04.2017 / 05:05

    0 answers