类泛型
public abstract class HttpCallBack<T> implements EngineCallBack {
protected abstract void success(T listResult);
}
方法泛型
private <T> T getView(int viewId){
return (T) findViewById(viewId);
}
private <T,P> T getView(int viewId,P str){
return (T) findViewById(viewId);
}
泛型的上限
protected void startActivity(Class<? extends Activity> clazz){
Intent intent = new Intent(this,clazz);
startActivity(intent);
}
- Class<?>?为通配符,可以不写。此时可以传任意Class对象,如:String.class
- Class<? extends Activity> 此时只能传Activity的子类
泛型的下限
protected void startActivity(Class<? super MainActivity> clazz){
Intent intent = new Intent(this,clazz);
startActivity(intent);
}