Generics used to write classes and methods


If it is used on a class

public abstract class AbstractBatchBaseDao<T>

Add <T> to the class name, after the description, it is defined to use this type

For example its subclasses like  

public class BatchAgentProfitDaoImpl extends AbstractBatchBaseDao<AgentProfitRecord>{
...


For example, put a method in AbstractBatchBaseDao
protected void doBatch(String sql, List<T> beanList){
...
setParameter(ps,bean); put this method, indicating that the subclass must implement this method
...
}

So there is also this method in the implementation class BatchAgentProfitDaoImpl
@Override
public void setParameter(PreparedStatement ps, AgentProfitRecord agentProfitRecord) {

	ps.setLong(1, agentProfitRecord.getBATID());




And if you use a generic method, it will be more flexible. paramable is an interface. Before the implementation is handed over to the client to implement the replacement, a setParameter method must be implemented from itself.

protected <U> void doBatch(String sql, List<U> beanList, JDBCParamable<U> paramable){

paramable.setParamter(ps, bean)

}

is an example of using interfaces instead of abstract classes

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326157334&siteId=291194637
Recommended