lundi 28 septembre 2015

return Class.forName instead of new instance

I've found this code inside an old project

public abstract class AireBatchDaoFactory {
     public static final String ORACLE_FACTORY = "airebatch.oracle.OracleDaoFactory";
     public static AireBatchDaoFactory getFactory(String factory) throws SQLException
     {
        try {
           return (AireBatchDaoFactory) Class.forName(factory).newInstance();
        } 
        catch (Exception e) {
            throw new SQLException("error msg");
        }
     }
     public abstract AireBatchDao getAireBatchDao() throws SQLException;}

I would like to understand the concrete difference beetween

return (AireBatchDaoFactory) Class.forName(factory).newInstance();

and

return new AireBatchDaoFactory();





Aucun commentaire:

Enregistrer un commentaire