aspose file tools*
The moose likes Beginning Java and the fly likes Array Indexes And Compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array Indexes And Compiling" Watch "Array Indexes And Compiling" New topic
Author

Array Indexes And Compiling

Craig Oliver
Greenhorn

Joined: Aug 25, 2003
Posts: 21
So far I have found Java to be very strict with compiling and run time exceptions if things are not spot on. I was surprised the following compiled and ran okay considering there is no index given for arguments array when printed by method1.
public class MyClass
{
public static void main(String arguments[])
{
MyClass mc = new MyClass();
mc.method1(arguments);
}
public void method1(String arguments[])
{
System.out.println(arguments);
}
}
I was expecting compile error. In C, this would make sense as it would be pointer to start of character array, but in Java I do not understand what happens here. When I ran as
>java MyClass a b
it printed stuff like [java.lang.String;@cac268
Why was no error given or what is story with no index given when reference array?
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140
Arrays are Objects in Java, so what you are seeing is the effect of calling the toString() method on the array Object - its the object reference rather than its actual contents.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array Indexes And Compiling
 
Similar Threads
tipsmart mock
About Overridden II (a Mock Question question...)
Passing null as a method argument
Generics questions
Bad constructor?