• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!