Code Monkey home page Code Monkey logo

Comments (4)

Shreyanshsingh23 avatar Shreyanshsingh23 commented on June 5, 2024

While it would be convenient to have a public constructor for HashBasedTable to support easier serialization and deserialization, it's important to note that the Guava library designers have intentionally chosen not to expose a public constructor for HashBasedTable. This design decision is likely due to the complexity and internal structure of the table, and they may have considered it safer to provide factory methods for creating instances.

If you still wish to have a public constructor for HashBasedTable, you could consider creating a wrapper class that extends HashBasedTable and exposes the constructor you need. This way, you can have a deserialization-friendly class while still keeping the internal implementation of HashBasedTable encapsulated.

from guava.

eamonnmcmanus avatar eamonnmcmanus commented on June 5, 2024

Could you say a bit more about the problem you are seeing? It should normally be possible to serialize and deserialize a HashBasedTable, as verified by this test. Are we talking about something other than Java Serialization?

A code sample that shows the problem would help us understand it.

If you still wish to have a public constructor for HashBasedTable, you could consider creating a wrapper class that extends > HashBasedTable and exposes the constructor you need.

Unfortunately that isn't possible as such. HashBasedTable doesn't have a visible constructor, so it can't be subclassed. But it would be possible to make a wrapper class that contains a HashBasedTable and use that for the serialization and deserialization. The ForwardingTable class would be useful for this.

from guava.

jrtom avatar jrtom commented on June 5, 2024

In general, these days Guava follows the guidance of Effective Java item 74 (2d edition; item 85 in the 3d edition): "Prefer alternatives to Java serialization". (Guava's "important warnings", item 4, is a consequence of this.)

Basically, Java serialization is fragile (because it depends on details of internal implementation which may change) and we don't recommend using it. This is why (for instance) the common.graph types we released several years ago don't implement Serializable.

from guava.

eamonnmcmanus avatar eamonnmcmanus commented on June 5, 2024

Closing for lack of response. @Dynasty-develop feel free to reopen if there is more to say.

from guava.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.