条件语句非空判断
if(TextUtils.isEmpty(username)){
return;
}
String name = username;
Edittext
非空判断,如果为空,则该edittext自动获取焦点 =>
if (TextUtils.isEmpty(username)) {
Toast.makeText(this, getResources().getString(R.string.editText_cannot_be_empty),
Toast.LENGTH_SHORT).show();
editText.requestFocus();
return;
}
instanceof
在多态关系中,需要强制类型转换前,通常先用 instanceof 进行一下类型判断
class A extends B {
}
class Main {
public void trans(){
B b = new B();
//将B强转为A
if(b instanceof B){
A a = (A) b;
}
}
}