Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

what is going on??

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey java ppl
Look at the code please
when i type this line
int[][]={{1,2,3},new int[1]};// it works fine but when i do this
int[][]={{1,2,3},{new int[1]}};//it gives comile time error
I don't understand what i am doing here??
Regards Denish
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Denish,
original message:
hey java ppl
Look at the code please
when i type this line
int[][]={{1,2,3},new int[1]};// it works fine but when i do this
int[][]={{1,2,3},{new int[1]}};//it gives comile time error
I don't understand what i am doing here??

Reply:
first thing . please post codes that compile.
e.g int[][] = ... doesnt make any sense because int[][] on LHS is a invalid syntax. Instead say int[][] a = ...
Now here is the explanation for your problem.
When the compiler sees brace i.e { in the array initializer list, the next thing it expects after it is array element. So in ur case the array element here is new int[] which is an array.
now its very clear that the declared array's second dimension is capable of holding only int array and not again array or array.
so {new int[1]} part of declaration is treated as if it is
{new int[1], null, null} etc.. got it.
Well, the compiler will not complain if the LHS is a 3 d array.
e.g
public class Test{
public static void main(String args[]){
int[][][] test1 = {new int[2][], {new int[2]}};
int[][][] test2={{{1,2,3},{2,3,4}},{new int[1]}};//it gives comile time error
}
}
will compile perfectly.
Let me know if that helps!
Because i am new to this list, can someone help me how to include the original post in reply and make it bold.
and include emoticons.
Vivek
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vivek bawge:
Because i am new to this list, can someone help me how to include the original post in reply and make it bold.
and include emoticons.
Vivek


Hi Vivek,
Reply with quote click on this icon at the top of message box

Smilies http://www.javaranch.com/ubb/smilies.html
Other useful tags http://www.javaranch.com/ubb/ubbcode.html

 
denish mehta
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u lot vivek.I got it
Regards Denish
 
vivek bawge
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jyotsna Clarkin:

Originally posted by vivek bawge:
[b]Because i am new to this list, can someone help me how to include the original post in reply and make it bold.
and include emoticons.
Vivek


Hi Vivek,
Reply with quote click on this icon at the top of message box

Smilies http://www.javaranch.com/ubb/smilies.html
Other useful tags http://www.javaranch.com/ubb/ubbcode.html
[/B]


Thanks Jyotsna
Welcome Denish
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic