Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

Object type to a primitive type directly

 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Report post to moderator
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




 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks, issue has been resolved so no comments please.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Report post to moderator
If you are referring to other threads, you would have been better to add this question to that thread. I am closing this discussion.
 
    Bookmark Topic Watch Topic
  • New Topic