The type List is not generic; it cannot be parameterized with arguments [HTTPClient]

前端 未结 4 1818
清歌不尽
清歌不尽 2020-12-08 02:08
import java.awt.List;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.I         


        
4条回答
  •  情话喂你
    2020-12-08 02:23

    Your import has a subtle error:

    import java.awt.List;
    

    It should be:

    import java.util.List;
    

    The problem is that both awt and Java's util package provide a class called List. The former is a display element, the latter is a generic type used with collections. Furthermore, java.util.ArrayList extends java.util.List, not java.awt.List so if it wasn't for the generics, it would have still been a problem.

    Edit: (to address further questions given by OP) As an answer to your comment, it seems that there is anther subtle import issue.

    import org.omg.DynamicAny.NameValuePair;
    

    should be

    import org.apache.http.NameValuePair
    

    nameValuePairs now uses the correct generic type parameter, the generic argument for new UrlEncodedFormEntity, which is List, becomes valid, since your NameValuePair is now the same as their NameValuePair. Before, org.omg.DynamicAny.NameValuePair did not extend org.apache.http.NameValuePair and the shortened type name NameValuePair evaluated to org.omg... in your file, but org.apache... in their code.

提交回复
热议问题