Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8400369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:32:47+00:00 2026-06-09T21:32:47+00:00

Following are some snippets from a jsp page: <%! ArrayList songList = new ArrayList<String>();

  • 0

Following are some snippets from a jsp page:

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

    <%
        songList = StoreSongLink.linkList;
        // linkList is a static variable in the class StoreSongLink
        // There the linkList is defined as public static ArrayList<String> linkList = new ArrayList<String>();
    %>

<%}  else {
       for (ArrayList<String> list : songList){}

%>

The code inside the else srciplet produces an error required java.util.ArrayList<String> found java.lang.Object. Why is this ? I do not understand the reason for this.

Why does the compiler say songList to be of type Object ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:32:48+00:00Added an answer on June 9, 2026 at 9:32 pm

    You should declare it explicitly at the start:

    ArrayList<String> songList = new ArrayList<String>();
    

    If you declare it like this:

    ArrayList songList = new ArrayList<String>();
    

    Then you are saying songList is an ArrayList of Objects, regardless of what is to the right of the =. Assignment doesn’t change this, so this:

    ArrayList songList = new ArrayList<String>();
    songList = StoreSongLink.linkList;
    

    does not change the type of songList, it’s still effectively ArrayList<Object>.

    If you fix the declaration, then your for loop should look like:

    for (String list : songList){}
    

    Because songList is array list of Strings. As you have it, Java extracts each Object from songList and tries to assign it to what you have declared to the left of :, which you have told it is an ArrayList<String>. It cannot convert the Object to ArrayList<String> (especially since the Object is really just a String underneath), so it throws an error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to post some java code snippets on wordpress.com using the following
following some example from Microsoft I created my custom MembershipProvider in my MVC application
I was using the following code to retrieve HTML snippets from a database table
Following is the code snippets taken from http://pietschsoft.com/post/2011/09/09/Tag-Editor-Field-using-jQuery-similar-to-StackOverflow.aspx // pre-selected tags values: [ 'javascript',
I'm new to jsp and have ran into some trouble. Initially, the jsp file
I was following the snippets from html5boilerplate.com (as well as something that is recommended
I have the following 2 code snippets. Assume I have a Parent class and
The following code snippet generates some warning messages when compiling: Cluster& Myclass::getCluster(const Point &p)
I have the following code snippet where some strings are initialized in the if
Consider the following HTML snippet containing some javascript utilizing prompt and unload . The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.