Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array store exception

 
gurpreet singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello frnds,

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

but
String[] objArr = new String[10];
objArr[0] = new Long(); // gives compile time exception
 
Dan Polak
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long IS A Object, but Long IS NOT A String
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic