Is it possible to reference a nested generic parameter in java?

前端 未结 5 843
孤街浪徒
孤街浪徒 2020-12-11 01:52

I\'m not sure what the technical term for this is, but consider an interface:

public interface SomeInterface {
     public T doSomething();
}
         


        
5条回答
  •  天涯浪人
    2020-12-11 02:22

    Well, I started a bounty on this question, and didn't know that SO's behavior was to award someone the answer (congratulations Daniel), I thought the rep would go unrewarded and I would lose it. Oh well.

    Anyway, I finally have my answer. From here:

    Unfortunately, for the purposes of backwards compatibility, new Map() indicates a raw type, and therefore cannot be used for type inference.

    So basically when creating a class and passing in the type parameter, type inference was disabled to leave room for the raw type. So in my case there could be some type inference but that would be a question of having a more complex different kind of type inference to handle this case, which wasn't done.

提交回复
热议问题