required java.util.ArrayList,found java.lang.Object : I do not understand the reason for this error

前端 未结 7 1284
逝去的感伤
逝去的感伤 2021-01-28 09:30

Following are some snippets from a jsp page:

<%! ArrayList songList = new ArrayList(); %>

    <%
        songList = StoreSongLink.linkLis         


        
7条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 10:09

    for (ArrayList list : songList){} // Error is here
    

    And you have define a reference of ArrayList of Object type and declared a String type ArrayList instance which should be ArrayList songList = new ArrayList(); or ArrayList songList = new ArrayList(); (supports only java 7)

    So the Corrected code could be like -

    <%! List songList = new ArrayList(); %>
    ...
    for (String list : songList){
    }
    

提交回复
热议问题