1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html lang="en">
3 <head>
4 <title>Value-based Classes</title>
5 <link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
6 </head>
7 <body>
8 <h2 id="ValueBased">Value-based Classes</h2>
9
10 Some classes, such as <code>java.util.Optional</code> and
11 <code>java.time.LocalDateTime</code>, are <em>value-based</em>. Instances of a
12 value-based class:
13 <ul>
14 <li>are final and immutable (though may contain references to mutable
15 objects);</li>
16 <li>have implementations of <code>equals</code>,
17 <code>hashCode</code>, and <code>toString</code> which are computed
18 solely from the instance's state and not from its identity or the state
19 of any other object or variable;</li>
20 <li>make no use of identity-sensitive operations such as reference
21 equality (<code>==</code>) between instances, identity hash code of
|
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <title>Value-based Classes</title>
5 <link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
6 </head>
7 <body>
8 <h2 id="ValueBased">Value-based Classes</h2>
9
10 Some classes, such as <code>java.util.Optional</code> and
11 <code>java.time.LocalDateTime</code>, are <em>value-based</em>. Instances of a
12 value-based class:
13 <ul>
14 <li>are final and immutable (though may contain references to mutable
15 objects);</li>
16 <li>have implementations of <code>equals</code>,
17 <code>hashCode</code>, and <code>toString</code> which are computed
18 solely from the instance's state and not from its identity or the state
19 of any other object or variable;</li>
20 <li>make no use of identity-sensitive operations such as reference
21 equality (<code>==</code>) between instances, identity hash code of
|