62,614
社区成员
发帖
与我相关
我的任务
分享
public interface X{
void foo(A input);
}
同时处理A或者B类实体。
void foo(A input){
if (input instanceof B){
ServiceB.verify(input, 100); // 随便写的verify接口,只是表明A,B的校验规则和参数不同
}else if(input instanceof A){
ServiceA。isValid(input);
}else{
throw new SomeException();
}
}
switch (input.class){
case B.class:
......
break;
case A.class:
......
break;
default:
......
}
switch(input.getClass().toString()){
case "com.xxx.A":
break;
case "com.xxx.B":
break;
}
java7的switch支持字符串比较了