Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

array store exception  RSS feed

 
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
Boost this thread!