This week's book giveaway is in the OCP forum. We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests and have Scott Selikoff and Jeanne Boyarsky on-line! See this thread for details.
1)Does Java allow you to cast an array name as an Object. What does that mean ? Is there any reason why that is allowed in Java? Is there any use for it ? For example the following code compiles fine. String [] strArray = new String[10]; Object obj = strArray;// What is the use of this ?
I think one possible purpose is the use of Vector remember the signature of the method add() add(Object o) Appends the specified element to the end of this Vector you can add an array to a vector you even do not need an explicit cast it is an automatic promotion from array to Object
It is the Java Design, that makes it more object oriented. In Java, array is a first class object. It also like all the other objects inherits from parent class Object. Therefore it has all the methods of the class Object. Regards Gunjan
I convert arrays to objects and back all the time in my applet to servlet pipeline. The pipeline takes one "Object" and that can be an array. On the other end, I convert it back to what I need.