Skip to main content
added 31 characters in body
Source Link
Kevin Welker
  • 8k
  • 1
  • 43
  • 56

Someone asked a question a few moments ago that got recalled because it was downvoted. It was clearly noted that enums themselves cannot be generic, but the question title was "generic enum method", and that of course is possible. The original question had some sample pseudo-Java code that went something like:

enum Test<T> {
    TEST1<T1>,
    TEST2<T2>,
    TEST3<T3>;
    // I missed some details they had here for overriding methods or such

   public T getInstance() {...
      // somehow returning a T1 when called on TEST1, a T2 for TEST2, etc.
   }
}

I am reasking, because I have a potential answer to post below, if it helps in his caseto what may have been the question (@Radu)behind the question from @Radu.

Someone asked a question a few moments ago that got recalled because it was downvoted. It was clearly noted that enums themselves cannot be generic, but the question title was "generic enum method", and that of course is possible. The original question had some sample pseudo-Java code that went something like:

enum Test<T> {
    TEST1<T1>,
    TEST2<T2>,
    TEST3<T3>;
    // I missed some details they had here for overriding methods or such

   public T getInstance() {...
      // somehow returning a T1 when called on TEST1, a T2 for TEST2, etc.
   }
}

I am reasking, because I have a potential answer to post below, if it helps in his case (@Radu).

Someone asked a question a few moments ago that got recalled because it was downvoted. It was clearly noted that enums themselves cannot be generic, but the question title was "generic enum method", and that of course is possible. The original question had some sample pseudo-Java code that went something like:

enum Test<T> {
    TEST1<T1>,
    TEST2<T2>,
    TEST3<T3>;
    // I missed some details they had here for overriding methods or such

   public T getInstance() {...
      // somehow returning a T1 when called on TEST1, a T2 for TEST2, etc.
   }
}

I am reasking, because I have a potential answer to below, to what may have been the question behind the question from @Radu.

Source Link
Kevin Welker
  • 8k
  • 1
  • 43
  • 56

Generic enum method

Someone asked a question a few moments ago that got recalled because it was downvoted. It was clearly noted that enums themselves cannot be generic, but the question title was "generic enum method", and that of course is possible. The original question had some sample pseudo-Java code that went something like:

enum Test<T> {
    TEST1<T1>,
    TEST2<T2>,
    TEST3<T3>;
    // I missed some details they had here for overriding methods or such

   public T getInstance() {...
      // somehow returning a T1 when called on TEST1, a T2 for TEST2, etc.
   }
}

I am reasking, because I have a potential answer to post below, if it helps in his case (@Radu).