Java boolean and null strangeness -
could please helpe me in understanding why code generate following output?
please note, f here debug purpose, f[0]=(lastline!=null) equivalent lastline!=null test, not bug.
boolean f[] = new boolean[6]; if (f[0]=(lastline!=null) // есть следующая строка || (f[1]=isedgetime) // конец сессии || (f[2]=td.gethour() <10) // или уже утро, после полуночи все свечки хороши || (f[3]=(td.gethour() == 23 && td.getminute() >=50)) || (f[4]=currserverhour > linehour) // или час сменился || (f[5]=currserverminutesperiod > linesminutesperiod) ){ answer.append(classcode).append(".") .append(tickerutils.getroot(ticker)) .append(";").append(minutes).append(";") .append(line) .append("\n"); system.out.println(arrays.tostring(f)); if (f[0]) system.out.printf("\"%s\" : %d, currserverminute=%d; %d > %d\n", lastline, (lastline!=null? 1: 0), currserverminute, currserverminutesperiod, linesminutesperiod); line = lastline; }
output:
[true, false, false, false, false, true] "null" : 0, currserverminute=50; 10 > 9
that can't understand why "lastline" not null, f[0]
true , @ same time lastline != null
gives me false, null, actually, how be?
if looks assigning f[0]
following :
(lastline!=null) // есть следующая строка || (f[1]=isedgetime) // конец сессии || (f[2]=td.gethour() <10) // или уже утро, после полуночи все свечки хороши || (f[3]=(td.gethour() == 23 && td.getminute() >=50)) || (f[4]=currserverhour > linehour) // или час сменился || (f[5]=currserverminutesperiod > linesminutesperiod)
therefore f[0]
can true though lastline
null.
try change condition to:
if ((f[0]=(lastline!=null)) // есть следующая строка || (f[1]=isedgetime) // конец сессии || (f[2]=td.gethour() <10) // или уже утро, после полуночи все свечки хороши || (f[3]=(td.gethour() == 23 && td.getminute() >=50)) || (f[4]=currserverhour > linehour) // или час сменился || (f[5]=currserverminutesperiod > linesminutesperiod) )
if want f[0]
contain value of (lastline!=null)
.
this take care of value of f[0]
. however, if f[i]
true i
, f[i+1]
won't evaluated due short circuit evaluation of ||
condition, you'll have @ 1 true
value in f
array. i'm not sure if that's want.
Comments
Post a Comment