Domanda

I found this code for a generic DAO interface while browsing around:

public interface GenericDAO<T, ID extends Serializable> {

    Class<T> getEntityClass();

    T findById(final ID id);

    List<T> findAll();
    List<T> findByExample(final T exampleInstance);

    List<T> findByNamedQuery(
        final String queryName,
        Object... params
    );

    List<T> findByNamedQueryAndNamedParams(
        final String queryName,
        final Map<String, ?extends Object> params
    );

    int countAll();

    int countByExample(final T exampleInstance);

    T save(final T entity);

    boolean delete(final T entity);
}

Is there any reason in particular for leaving methods with the default access modifier (class/package: yes, subclass/world: no)?

P.S: An added question. Are IDs usually found in implementations which don't depend on a RDBMS (XML, flat file...) ?

È stato utile?

Soluzione

Methods of an interface are implicitely public. Using the public modifier is thus redundant and unnecessary.

Checkstyle even has a rule to check that public is not used in interface methods.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top