Question

When using a wildcards some methods (e.g. ArrayList.set) cannot be used and return an error message similar to

The method set(int, capture#3-of ?) in the type List is not applicable for the arguments (int, String)

I have read why this is the case and would like to know how this is done. That is how does the compiler know that some methods are applicable (e.g. List.get(int)) but others are not?

Was it helpful?

Solution 2

Compiler assgins special tokens (capture#3-of ?) to each occurence of wildcard and use regular method applicability rules (JLS 15.12.2).

Since captures of wildcards are not compatilbe with other types and with other captures, "method not applicable" is produced.

OTHER TIPS

All applicable rules are in the Java Language Specification #15.12.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top