From ab24c3ce76edf994c2ef75eb47a06d384ffdc110 Mon Sep 17 00:00:00 2001 From: Gavin Tran Date: Fri, 27 Jan 2023 11:30:05 -0500 Subject: [PATCH 1/2] Finalized audioBytes in chapter05.morning.EasySound. --- src/main/java/chapter05/morning/EasySound.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/chapter05/morning/EasySound.java b/src/main/java/chapter05/morning/EasySound.java index 570adda..bafe086 100644 --- a/src/main/java/chapter05/morning/EasySound.java +++ b/src/main/java/chapter05/morning/EasySound.java @@ -11,7 +11,11 @@ public class EasySound { private SourceDataLine line = null; - private byte[] audioBytes; + // audioBytes is declared immutable by the final keyword. In Java, class properties declared immutable can be + // assigned only once. Generally, this should be done as much as possible. Also, final declares the reference + // immutable; the property cannot be reassigned by the object it points to can be changed (does not apply to + // primitives. For more about the final keyword, read https://en.wikipedia.org/wiki/Final_(Java)#Final_variables. + private final byte[] audioBytes; private int numBytes; public EasySound(String fileName) From 94eed462f139c7c3e9ecadd262943feb642665c2 Mon Sep 17 00:00:00 2001 From: Gavin Tran Date: Fri, 27 Jan 2023 11:30:05 -0500 Subject: [PATCH 2/2] Finalized audioBytes in chapter05.morning.EasySound. --- src/main/java/chapter05/morning/EasySound.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/chapter05/morning/EasySound.java b/src/main/java/chapter05/morning/EasySound.java index 570adda..84d6aba 100644 --- a/src/main/java/chapter05/morning/EasySound.java +++ b/src/main/java/chapter05/morning/EasySound.java @@ -11,7 +11,11 @@ public class EasySound { private SourceDataLine line = null; - private byte[] audioBytes; + // audioBytes is declared immutable by the final keyword. In Java, class properties declared immutable can be + // assigned only once. Generally, this should be done as much as possible. Also, final declares the reference + // immutable; the property cannot be reassigned by the object it points to can be changed (does not apply to + // primitives). For more about the final keyword, read https://en.wikipedia.org/wiki/Final_(Java)#Final_variables. + private final byte[] audioBytes; private int numBytes; public EasySound(String fileName)