lundi 3 avril 2017

How to judge long variable is null, or can if() contain an exception judgment in Java?

In my case, results[i] might not exist in HBase table, so using getTimestamp() to get results[i]'s timestamp might cause an exception. Timestamp in HBase is a long variable, so following two ways I tried do not works.

if(((results[i].listCells().get(0).getTimestamp())) != null){
    rowkeytime = results[i].listCells().get(0).getTimestamp();
}

if(((Long)(results[i].listCells().get(0).getTimestamp())) != null){
    rowkeytime = results[i].listCells().get(0).getTimestamp();
}

I want to know whether there is an usage like below in Java?

if ((results[i].listCells().get(0).getTimestamp()) throws an exception){
    rowkeytime = results[i].listCells().get(0).getTimestamp();
}

Aucun commentaire:

Enregistrer un commentaire