Internal static enumeration as a generic type?

I study and experiment with Java generics and come up with the following piece of code that does not compile as expected. Result cannot be resolved . I means input, O for output.

 public interface Stats<I, O> { O addItem (int index, I item); } public class AStats implements Stats<Item, Result> { public static enum Result { SUCCESS1, SUCCESS2, ERROR; } @Override public Result addItem (int index, Item item) { //valid code } } 
  • Is there a more elegant solution than declaring a Result in a separate file?

  • Is it really bad to have a method that returns an instance of a generic type?

+4
source share
1 answer
  • Your class name is AStats.Result , not Result :

     public class AStats implements Stats<Item, AStats.Result> { ... } 
  • I don't think returning an instance of a generic inner type is a bad idea.

+8
source

All Articles