I just play with my code. The code in the if else block can be written with a conditional statement (? :). how to write the following code with a conditional statement.
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:
Several markers on this line
Type mismatch: cannot convert from null to boolean
Syntax error on token "! =", Invalid AssignmentOperator
Here you can use the ternary operator (using a dummy logical and not using again):
boolean dummy = doc != null ? doc.close() : false;
. , "1-" , - :
if (doc!=null) doc.close();
EDIT:
, :
, , .
dummy
doc
null
. .
//if(doc!=null){ // doc.close(); //}
, . , . , .
Source: https://habr.com/ru/post/1617960/More articles:how to add multiple text images with image in edittext in android - androidЗапуск теста @Ignored JUnit в Eclipse - eclipseHow to run a Pregel Shortest Path by creating all vertices as the source vertex once on Spark Cluster - scalaAndroid - openCV, get part of an image - weird behavior - javagit cherry pick configuration - gitHow to enable WebView in Objective-C without crashing - objective-cDetecting dead code in Java at runtime - javaCheck if function a from one.js from two.js exists - javascriptOverride static var in Swift child class - overrideSelect the column and row values with the index in the data frame - rAll Articles