Loading...
Loading...
Browse 5 real-world technical and behavioral interview questions about Immutability. Review scenarios, edge cases, and architectural best practices.
Store money as immutable double-entry rows where every movement writes at least two balanced entries, derive balances by summing those entries, correct mistakes with compensating entries instead of updates, and keep each currency in its own denominated account so nothing is ever summed across units.
Thread-safe component design starts by assigning every field a policy: confined, immutable or guarded by a named lock. Method-level synchronization is not enough because atomic methods do not compose into atomic workflows.
A constructor is the default and needs no justification. A static factory earns its place when construction can return a cached or alternative implementation, or needs a name; a builder when there are many optional fields. Singleton is usually a testability liability.
Equal objects must produce equal hash codes. Break that and a HashMap sends lookups to a bucket the entry was never placed in, so the map holds a value you can no longer retrieve and a set silently admits duplicates. The same failure appears later if a key is mutated after insertion.
Because `is` compares identity while `==` compares value, and CPython reuses objects for small integers and for compile-time string constants. The agreement is an implementation detail of the interpreter you happen to be running, so code that relies on it works until the values change. It also connects interning to the point an interviewer is testing.