mardi 25 août 2015

How to use Final Variables belonging to one block in another? - JAVA

final int a,b;

if(condition1)
 {
  a=cal.get(Calendar.HOUR);
  b=cal.get(Calendar.MINUTE);
 }

if (condition2)
 {
  int c=b+a;
  display(c);
 } 

In this type of code the compiler is asking to intialize a and b, which I can't do until the condition1 is met. and a and b being final is mandatory as the values of hours and minutes keep changing. The above written code is very generalized just to give you an idea of my problem.

Aucun commentaire:

Enregistrer un commentaire