forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperatureReading.java
More file actions
31 lines (30 loc) · 907 Bytes
/
TemperatureReading.java
File metadata and controls
31 lines (30 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// references/TemperatureReading.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Cloning a composed object
package references;
public class TemperatureReading implements Cloneable {
private long time;
private double temperature;
public TemperatureReading(double temperature) {
time = System.currentTimeMillis();
this.temperature = temperature;
}
@Override public TemperatureReading clone() {
try {
return (TemperatureReading)super.clone();
} catch(CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
public double getTemperature() {
return temperature;
}
public void setTemperature(double temp) {
this.temperature = temp;
}
@Override public String toString() {
return String.valueOf(temperature);
}
}