equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
27 */ |
27 */ |
28 |
28 |
29 import java.io.*; |
29 import java.io.*; |
30 |
30 |
31 class Foo implements Serializable { |
31 class Foo implements Serializable { |
|
32 private static final long serialVersionUID = 1L; |
|
33 |
32 final int i; |
34 final int i; |
33 |
35 |
34 Foo(int i) { |
36 Foo(int i) { |
35 this.i = i; |
37 this.i = i; |
36 } |
38 } |
38 public boolean equals(Object obj) { |
40 public boolean equals(Object obj) { |
39 if (! (obj instanceof Foo)) |
41 if (! (obj instanceof Foo)) |
40 return false; |
42 return false; |
41 Foo f = (Foo) obj; |
43 Foo f = (Foo) obj; |
42 return (i == f.i); |
44 return (i == f.i); |
|
45 } |
|
46 |
|
47 public int hashCode() { |
|
48 return i; |
43 } |
49 } |
44 } |
50 } |
45 |
51 |
46 public class FinalFields { |
52 public class FinalFields { |
47 public static void main(String[] args) throws Exception { |
53 public static void main(String[] args) throws Exception { |
66 f2copy = (Foo) oin.readObject(); |
72 f2copy = (Foo) oin.readObject(); |
67 |
73 |
68 if (! (f1.equals(f1copy) && f2.equals(f2copy))) |
74 if (! (f1.equals(f1copy) && f2.equals(f2copy))) |
69 throw new Error("copies don't match originals"); |
75 throw new Error("copies don't match originals"); |
70 } |
76 } |
|
77 |
71 } |
78 } |