wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array store exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array store exception" Watch "array store exception" New topic

array store exception

gurpreet singh
Ranch Hand

Joined: Apr 07, 2006
Posts: 38
Hello frnds,

pls explain why does
Object[] objArr = new String[10];
objArr[0] = new Long(); // compiles; fails at runtime

String[] objArr = new String[10];
objArr[0] = new Long(); // gives compile time exception

Dan Polak
Ranch Hand

Joined: Nov 06, 2006
Posts: 32
Long IS A Object, but Long IS NOT A String

<a href="http://www.dantheman.pl" target="_blank" rel="nofollow">http://www.dantheman.pl</a>
subject: array store exception
Similar Threads
Generic arrays
String to Object array
Need more info on toArray(Object[])
Collection toArray( T[ ] ) method