Java Type Witness Generic
Ayman Patel
Back End Engineer @ MastercardLinks
- Type Witness
This statement expects to receive an instance of List<String> which is the target type. Because emptyList() returns List<T>, the compiler infers that type argument T must be String. Java 7 and Java 8 support this inference. Alternatively, you could employ a type witness and specify T's value as shown below:
Another example: