aspose file tools*
The moose likes Beginning Java and the fly likes Object type to a primitive type directly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Object type to a primitive type directly

Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Java 7 feature:The ability to cast from an Object type to a primitive type directly i.e

int i=0;
Object o=i;
i=(int)o;

Then why doesn't it work with my code ?

---------- Run ----------
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at ListDemo.main(ListDemo.java:10)

Output completed (0 sec consumed) - Normal Termination

for my code detail please refer this link.


getObject

public final Object getObject(String key)

Gets an object for the given key from this resource bundle or one of its parents. This method first tries to obtain the object from this resource bundle using handleGetObject. If not successful, and the parent resource bundle is not null, it calls the parent's getObject method. If still not successful, it throws a MissingResourceException.

Parameters:
key - the key for the desired object
Returns:
the object for the given key
Throws:
NullPointerException - if key is null
MissingResourceException - if no object for the given key can be found





OCA7
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Thanks, issue has been resolved so no comments please.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39395
    
  28
If you are referring to other threads, you would have been better to add this question to that thread. I am closing this discussion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object type to a primitive type directly