1. 程式人生 > >java 判斷型別instanceof,不要再用try catch了

java 判斷型別instanceof,不要再用try catch了

1.以前老是用try catch來判斷物件型別,現在要用instanceof了,特別是spring integration有比較多會傳遞不同的payload type

if( sth instanceof String){

//string type

}else if(sth instanceof Integer){

//Integer type

}