How is a type argument inferred to invoke a generic method?

Has such a method?

public <P, T extends List<P>> T getAwesomeList() { // ... } 

Why is this compiling without any warnings?

 Set<String> test = getAwesomeList(); 

I think this has something to do with generic erasure, but I'm not sure why this is not picked up by the compiler. This happens on Java 7, on 8 you get a compilation error.

What has changed to J8 for this, so as not to compile?

Update:

After a double check, it also compiles in Java 8.

+6
source share

Source: https://habr.com/ru/post/1015588/


All Articles