Static method in a generic class?

In Java, I’d like to have something as:

class Clazz<T> {
  static void doIt(T object) {
    // ...
  }
}

But I get

Cannot make a static reference to the non-static type T

I don’t understand generics beyond the basic uses and thus can’t make much sense of that. It doesn’t help that I wasn’t able to find much info on the internet about the subject.

Could someone clarify if such use is possible, by a similar manner? Also, why was my original attempt unsuccessful?

12 Answers
12

Leave a Comment