Correct me if I am wrong, wouldn't this thing produce a compiler error at the line that says
since i>10 gives me boolean value which & don't take? Or is it a runtime error since express are evaluated during runtime...either way I thought & is a bitwise operator that only take integer, while boolean is never evaluated as integers.
The value of j would be 1 at line 17. methodB() will be called only once,i.e in b=i>10 & methodB(1); Here, b=i>10 && methodB(2);
i>10 is false,so the methodB() will not be called. [ June 26, 2002: Message edited by: geetha nagarajan ]
Chung Huang
Ranch Hand
Joined: Jun 21, 2002
Posts: 56
posted
0
Never mind, forgot about that short-circut nature wouldn't j be 2? the call send over 2, and the line says j += k where j is 0 and k is the value send over which is 2. [ June 26, 2002: Message edited by: Chung Huang ]
geetha nagarajan
Ranch Hand
Joined: Jul 13, 2001
Posts: 94
posted
0
& can take both boolean and integral operands. && can be applied to boolean expressions only.
To geetha I thought the & operand is not short cutted! only && is short-cutted. I thought the second operand always gets evaluated even if the first operand evaluates to false. but if you use && then if the result can be determined, then the second operand doesn't get evluated? correct me please.
Amir
geetha nagarajan
Ranch Hand
Joined: Jul 13, 2001
Posts: 94
posted
0
To Amir, Yes, && is short-circuited and not &. Both operands r evaluated in case of &.
we always have to be aware of these little errors. Francisco
Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">here</a> to see an example.
huanyu zhao
Greenhorn
Joined: Feb 22, 2001
Posts: 29
posted
0
Originally posted by geetha nagarajan: The value of j would be 1 at line 17. methodB() will be called only once,i.e in b=i>10 & methodB(1); Here, b=i>10 && methodB(2);
i>10 is false,so the methodB() will not be called. [ June 26, 2002: Message edited by: geetha nagarajan ]