• Post Reply Bookmark Topic Watch Topic
  • New Topic

Type Mismatch  RSS feed

 
Abhinav Pande
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we write



and pass



Note: Its a type mismatch error. how to fix it.


 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming from the context of your question, what you are trying to do is pass in the array by creating it at the point it is needed. What we call this is Java is an anonymous array. Its declaration syntax is demonstrated in the following.

We have the method that you are using in a class


Code that uses the method



From this example you are passing in the array as an argument to the method by creating it on spot and the syntax to do this is new (Any Type)[]{}. The reason you must use the new keyword is because any array in Java is an object and to instantiate any object in Java you must use the new keyword followed by the type you are creating.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!