Generic Methods and Type Inferencing in Java

前端 未结 3 581
攒了一身酷
攒了一身酷 2021-02-06 04:41

Given the following not-very-useful code:

package com.something;

import java.util.ArrayList;
import java.util.Collectio         


        
3条回答
  •  心在旅途
    2021-02-06 05:24

    While the compiler does not infer the generic type one might intend, it will enforce type constraints that are explicitly specified. The following invocation results in a type error.

    this.plain("", new ArrayList()); /* Compiler error. */
    

    The parameterized method plain(String, String) of type Test is not applicable for the arguments (String, ArrayList)

提交回复
热议问题