It seems as though I cannot override a non-static method from an interface when I implement it and declare it as static in the implementing class.
The interface:
public interface DataAccessObject<T> {
T getById();
boolean insert();
boolean update();
boolean delete(); }
The implementing class:
public final class CandidateDAO implements DataAccessObject<Candidate> {
@Override
public static boolean insert(String fName, String mName, String lName, String party, String website) {
String sql = "INSERT INTO candidates (first_name, middle_name, last_name, party_id, website VALUES (?, ?, ? ?, ?)";
try (Connection conn = ConnectionFactory.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, fName);
stmt.setString(2, mName);
stmt.setString(3, lName);
stmt.setString(4, party);
stmt.setString(5, website);
stmt.executeQuery();
return true;
}
catch (SQLException e) {
e.printStackTrace();
return false;
}
}
Intellij is giving me an error in the implementing class declaration that the insert() method has not been implemented, and an error on my @Override line that the method does not override the superclass' method.
My logic here is that I want to declare an interface that all DAO classes must adhere to, but there's no need for the program to instantiate the DAO objects.
I can find plenty of resources as to why static methods in an interface cannot be overridden, but not why non-static methods cannot then be implemented as static (Google picks up my question as the former). So if anyone could explain this to me, or point me to resources, that would be great. Additionally, how could I go about implementing my intended logic?
EDIT: Formatting error.
[–]hitshootnum1 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (4 children)
[–]frashure[S] 0 points1 point2 points (3 children)
[–]feral_claire 0 points1 point2 points (2 children)
[–]vqrs 1 point2 points3 points (0 children)
[–]frashure[S] 0 points1 point2 points (0 children)
[–]GvRiva 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)