This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

cloning  RSS feed

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is from Dan's mock exam (question 19 of multidimensional arrays). His question is essentially whether this works or not, which it does.



I thought clone meant to do a bitwise copy of all of the member values. My question is- Where is it correct and legal to do casts of a cloned object into another object?

So in the above, the Object array is an array of references. It gets a copy of the array of references to arrays.

It appears that once you clone an array, you can assign it to an array of any superclass
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Tom Tolman:
where is it correct and legal to do casts of a cloned object into another object?
...It appears that once you clone an array, you can assign it to an array of any superclass



Or more correctly, an array of references is assignable to an array of "references of any superclass" type.

Cloning has little to do with it.

You can assign an array of references to an array of Objects. You can't assign an array of primitives to anything, even though the elements of the array may be convertible.

For example, the elements 1,2,3 as int are convertible to lL, 2L, 3L, however an array of them is not.

However object references work sorta the opposite way. If an array has references to an object of a subclass, it can be assigned to an array of references of a superclass.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!