wood burning stoves 2.0*
The moose likes Java in General and the fly likes unchecked  cast exception from object to String[] conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "unchecked  cast exception from object to String[] conversion" Watch "unchecked  cast exception from object to String[] conversion" New topic
Author

unchecked cast exception from object to String[] conversion

Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278

Hi all
I get this 'unchecked cast exception from object to String[] conversion' so i have to suppress warnings for now.

outputMap is always map of <String,object>
What can i do to do type-safe casting as i do want to keep warnings suppressed.





Thanks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

Casting is never type-safe: there's always the possibility of getting a ClassCastException at runtime when you do a cast. So, it's best to avoid having to cast as much as possible.

What framework are you using to do that database query? Does it always return a Map<String, Object> when you do a query? If yes, and you cannot change it, then you'll be forced to cast the Object value to something that you can use (such as a List<String[]> in your example).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278

I am using spring framework jdbc 3 for db access

Class SimpleJdbcCall has this method
Map<String,Object> execute() - Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations.
I guess i would have to do the same i.e. suppress warnings .

Thanks a lot.
 
Don't get me started about those stupid light bulbs.
 
subject: unchecked cast exception from object to String[] conversion