-1

I defined the following interface and class

public interface Storeable {
     public static String getId() {
        return "id";
    }
}

public class ABC implements Storeable{
    public static String getId() {
         return "id2";
     }
}

Further, I defined the following method where I get an error-message "The method getId() is undefined for the type T":

public static <T extends Storeable> T getItem(String id) {

    Class<T> classOfT;
    T.getId();
....
}

Why is this not working? Eclipse Quick-Fix simply creates a further static method in the interface

user3579222
  • 1,103
  • 11
  • 28
  • You cant use a static method in a generic context. The whole point of generics in the context of your example is to work with polymorphism, and static and polymorphism don't go together. – GhostCat Jul 30 '18 at 08:33

1 Answers1

1

You access static methods by the type directly, so use Storeable.getId()

You cannot override a static method.

Sam
  • 670
  • 1
  • 6
  • 20