Integer is String - how can that be?
<p>Something terribly wrong is happening.</p>

<p>I have </p>

<pre><code>ArrayList&lt;Integer&gt; activitiesToDelete;
</code></pre>

<p>I need to prepare array of objects to pass to Spring jdbcTemplate. However for some reason element in ArrayList is treated as String, so breaks at the point of execution of jdbcTemplate, complaining that it can't convert from String to int. Then I tried to convert within the loop to see if that would help :-\ And I obviously can't do Integer.parseInt as IDE treats it correctly as Integer. Whenever I assign Integer a = activitiesToDelete.get(i); It gives me:</p>

<pre><code>java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
</code></pre>

<p>Same for int a = ...
How can that be?</p>

<pre><code> Object [] objectList = new Object [activitiesToDelete.size()];

    for (int i = 0; i &lt; activitiesToDelete.size(); i++) {

    Integer a = activitiesToDelete.get(i);

        logger.info(String.valueOf(activitiesToDelete.get(i)));

        objectList[i] = activitiesToDelete.get(i).intValue();
}

    jdbcTemplate.update(sql, objectList);
</code></pre>

<p>What am I missing in here?</p>

<p><strong>UPDATE: Culprit line</strong></p>

<pre><code>  @RequestMapping(value="/activities/delete", method = RequestMethod.POST) public String deleteActivities(@RequestParam("activityId") ArrayList &lt;Integer&gt; activitiesToDelete) 
</code></pre>

<p><strong>This is a snippet related to Spring MVC where it gets populated from form, it seems that Spring can't add proper types to the ArrayList.</strong></p>

<p>Anyone wondering, either use int[] or HttpServlet methods(extra code though).</p>
