Nikolay Kuznetsov
Nikolay Kuznetsov

Reputation: 9579

Inner static enum as generic type?

I am learning and experimenting with Java generics and come up with following piece of code which does not compile as expected. Result cannot be resolved. I stands for 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
    }
}

Upvotes: 4

Views: 192

Answers (1)

Crozin
Crozin

Reputation: 44376

  1. Your classname is AStats.Result, not Result:

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

Upvotes: 8

Related Questions