[Java] Explicit Array Size

I've read several examples from the net and want to verify this
Java doesn't allow explicit sized arrays
like this
  1. class A
  2. {
  3.       public A()
  4.       {
  5.       }

  6.      float data1[2];  <<<<<<<< wrong
  7.      float data2[];    <<<<<<<< correct
  8. }
複製代碼

try this la
float value[]=new float[2];

then push data into the array
value[0]=1;
value[1]=2;



[ 本帖最後由 xeon0541 於 2009-9-4 16:32 編輯 ]

TOP

原帖由 xeon0541 於 2009-9-4 16:30 發表
try this la
float value[]=new float[2];

then push data into the array
value[0]=1;
value[1]=2;



Thanks I understand that now. And I have one more question
Is that how can you "pass by reference" like in C++?
like
func(A& data);
in java?

I also read some java articles. Seems like you  have to do some tricks on that..

Thanks

[ 本帖最後由 luckiejacky 於 2009-9-4 16:49 編輯 ]

TOP

回覆 3# 的帖子

Objects are always "pass by reference" in Java.
But primitives(char, int, long, etc..) are "pass by value".

TOP

原帖由 Tin852 於 2009-9-4 16:48 發表
Objects are always "pass by reference" in Java.
But primitives(char, int, long, etc..) are "pass by value".


謝謝...

TOP