• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does an array implements Serializable automatically ?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear ranchers,

Does an array implements Serializable automatically ?

For instance :



The result is true, but why? AClass doesn't implement Serializable but the array does.
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because internally Arrays are objects and the class for declaring arrays can't be modified by us and we need to have arrays serialized at times and hence the designers give Arrays the power of serialization by default.

Bury that into your soul: Arrays are serializable by default.
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
api states java.util.Arrays to be

it neither mentions of serializable or not being able to modify the arrays class by extending it. But when tested
it sure gives an error stating Arrays() have a private access in java.util.Arrays.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java arrays are not included in the API documentation, but they are described in the JLS. See JLS - 10.7 Array Members...

An array thus has the same public fields and methods as the following class:


Milan, the java.util.Arrays class in the API is not an array. It is a utility class containing static methods for working with arrays. (Its constructor is private, so it can't be instantiated from outside the class.)
 
Milan Sutaria
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Marc for correcting me
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic