Win a copy of Pragmatic AI this week in the Artificial Intelligence 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

multidimensional array question  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the following code:


Can someone please explain why the following assignment is legal:


and why is the following not legal.

thanks.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Alfonso Harding:
From the following code:


Can someone please explain why the following assignment is legal:


and why is the following not legal.

thanks.


b2 is a 4-dimensional array and b is a 2-dimensional array so when you have N subscripts following an N-dimensional array that will evaluate to a simple element. In the first statement you had b2 [0][1][0][0] which indeed evaluates to a simple byte and b [0][0] which also evaluates to byte. Now if you have fewer subscripts than dimensions, then it will evaluate to an array of N-S dimensions where S is the number of subscripts that follows the reference. In the second example you had b2 [1][1][0] or a 4-3=1 dimensional array. Java being a strong typed language vetos your trying to set an array to a primitive.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!