java - A extends B implements C,B extends D,使用A instanceof D是false
阿神
阿神 2017-04-17 15:07:46
0
3
886
public class XXXFragment extends BaseFragment implements XXXClick{
    method(){
        ABC.method(this);
    }
}
public class XXXActivity extends BaseActivity implements XXXClick{
    method(){
        ABC.method(this);
    }
}
XXXFragment 是Fragment的子类;XXXActivity 是Activity的子类
public class ABC{
    method(Object obj){
        if(obj instanceof Activity){
            ...
        }else{
             if(obj instanceof Fragment){
                ...
             }
        }

    }
}
阿神
阿神

闭关修行中......

reply all(3)
Ty80

I know how to solve the problems I encountered. . . Thank you upstairs. When passing this, I can directly convert it into the required object to solve my needs. .

伊谢尔伦
BaseFragment  extend  BaseActivity ?
迷茫

The instanceof operator returns true if object is an instance of class. If object is not an instance of the specified class, or object is null, returns false

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template