cmbhatt
Harish Paravasthu
If you replace
if( "test" instanceof String)
String s = (String)"test";
with
String s = null;
if( "test" instanceof String)
s = (String)"test";
it will work
Best Wishes,<br /> Yeming
Originally posted by Yeming Hu:
pretty strange, is it a bug?
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
No. A local variable declaration statement cannot be used as the consequent statement executed by an if. See the JLS link posted above.
Best Wishes,<br /> Yeming
Originally posted by Barry Gaunt:
No. A local variable declaration statement cannot be used as the consequent statement executed by an if. See the JLS link posted above.
Best Wishes,<br /> Yeming
[My Blog]
All roads lead to JavaRanch
Originally posted by Satou kurinosuke:
What I think about it is that local variables must be declared in blocks, and a one line (ExpressionStatement) is not a block.
Please refer to http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.2
Best Wishes,<br /> Yeming
debasmita
Originally posted by Satou kurinosuke:
Does it make sense to declare a variable as a statement, where it can never be used ?
Best Wishes,<br /> Yeming
Originally posted by Yeming Hu:
I just check the BNF for if_statement of Java, It seems to me that local variable declaration statement is not forbidden as the consequent statement executed by an if, see BNF for if_statement of Java. Therefore, I am pretty confused now. Look forward to your answer and thanks in advance.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
In my opinion that BNF is wrong. The JLS states that a statement is:
None of those is a local variable declaration.
Anyway, as previously noted: declaring a variable as the only statement is rather meaningless because you cannot use it in the subsequent code.
Best Wishes,<br /> Yeming
debasmita
debasmita
debasmita
Is this what you wanted to convey?
and moreover is it like it happens with all the local instance variable that we try to decalre then only we get this error?
[My Blog]
All roads lead to JavaRanch
debasmita
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|