Announcement Announcement Module
No announcement yet.
Spring 3 queryForList Returntypechanged Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3 queryForList Returntypechanged

    I was trying to Include the spring3 m3 jars into my project and found that return type of queryForList has been changed from List<Map> to List<Map<String, Object>. This seems to throw compilation problems. I use jdk 1.5_011.

    Can this be taken care before the actual release of the product.


  • #2
    "seems to throw compilation problems" is a bit vague - could you be more specific, maybe post your code and the actual error you are seeing?


    • #3
      Code is
      List<Map> list = jdbcTemplate.queryForList(someQuery);

      Problem is (on Myeclipse)

      Cannot cast from List<Map<String,Object>> to List<Map>

      Problem from javacing using Ant is

      inconvertible types
      found : java.util.List<java.util.Map<java.lang.String,java .lang.Object>>
      required: java.util.List<java.util.Map>
      ================================================== ========

      It seems weird to me too as Java should technically be looking only @ list and not anything else.

      Both myeclipse and my ant script seemed to throw compilation problem.


      • #4
        List<Map> is not the correct return type for queryForList in either Spring 2.5 or Spring 3.0.

        The correct type is

        for Spring 2.5: List
        for Spring 3.0: List<Map<String, Object>>

        Both of these return types work with Spring 2.5 and 3.0.

        List<Map> works with 2.5 since Java can cast from List to List<Map>. When we add generics in 3.0, the return type changes to List<Map<String, Object>> and this can't be cast to List<Map>, so you get a compilation error.