I am just playing with my code. The code in if else block can be written with conditional operator (? :). how to write following code with Conditional Operator.
import com.itextpdf.text.Document;
public class TEst {
public static void main(String[] args) {
Document doc=null;
try{
doc=new Document();
//some operation.
}catch(Exception e){
}finally{
doc!=null? doc.close():"";
//if(doc!=null){
// doc.close();
//}
}
}
Eclipse suggestion :
Multiple markers at this line
Type mismatch: cannot convert from null to boolean
Syntax error on token "!=", invalid AssignmentOperator