diff --git a/src/effectivejava/chapter11/item83/Initialization.java b/src/effectivejava/chapter11/item83/Initialization.java index 15f40bff..83f05e0c 100644 --- a/src/effectivejava/chapter11/item83/Initialization.java +++ b/src/effectivejava/chapter11/item83/Initialization.java @@ -25,6 +25,7 @@ private static class FieldHolder { // Double-check idiom for lazy initialization of instance fields - Page 334 private volatile FieldType field4; + // NOTE: The code for this method in the first printing had a serious error (see errata for details)! private FieldType getField4() { FieldType result = field4; if (result != null) // First check (no locking) @@ -38,6 +39,7 @@ private FieldType getField4() { } + // Single-check idiom - can cause repeated initialization! - Page 334 private volatile FieldType field5; diff --git a/src/effectivejava/chapter5/item28/Chooser.java b/src/effectivejava/chapter5/item28/Chooser.java index 5eaa1903..259ab264 100644 --- a/src/effectivejava/chapter5/item28/Chooser.java +++ b/src/effectivejava/chapter5/item28/Chooser.java @@ -6,7 +6,7 @@ import java.util.Random; import java.util.concurrent.ThreadLocalRandom; -// List-based Chooser - typesafe (Page 120) +// List-based Chooser - typesafe (Page 129) public class Chooser { private final List choiceList; @@ -18,4 +18,15 @@ public T choose() { Random rnd = ThreadLocalRandom.current(); return choiceList.get(rnd.nextInt(choiceList.size())); } + + public static void main(String[] args) { + List intList = List.of(1, 2, 3, 4, 5, 6); + + Chooser chooser = new Chooser<>(intList); + + for (int i = 0; i < 10; i++) { + Number choice = chooser.choose(); + System.out.println(choice); + } + } } diff --git a/src/effectivejava/chapter5/item29/technqiue1/Stack.java b/src/effectivejava/chapter5/item29/technqiue1/Stack.java index 5d7b2930..fbaa60b7 100644 --- a/src/effectivejava/chapter5/item29/technqiue1/Stack.java +++ b/src/effectivejava/chapter5/item29/technqiue1/Stack.java @@ -3,7 +3,7 @@ import java.util.Arrays; -// Generic stack using E[] - Pages 130-133 +// Generic stack using E[] (Pages 130-3) public class Stack { private E[] elements; private int size = 0; diff --git a/src/effectivejava/chapter5/item29/technqiue2/Stack.java b/src/effectivejava/chapter5/item29/technqiue2/Stack.java index f7e62cc2..bf1632d3 100644 --- a/src/effectivejava/chapter5/item29/technqiue2/Stack.java +++ b/src/effectivejava/chapter5/item29/technqiue2/Stack.java @@ -3,7 +3,7 @@ import java.util.Arrays; import effectivejava.chapter5.item29.EmptyStackException; -// Generic stack using Object[] - Pages 130-133 +// Generic stack using Object[] (Pages 130-3) public class Stack { private Object[] elements; private int size = 0; diff --git a/src/effectivejava/chapter5/item30/GenericSingletonFactory.java b/src/effectivejava/chapter5/item30/GenericSingletonFactory.java index 40cd9cf8..6f27af8b 100644 --- a/src/effectivejava/chapter5/item30/GenericSingletonFactory.java +++ b/src/effectivejava/chapter5/item30/GenericSingletonFactory.java @@ -1,10 +1,8 @@ package effectivejava.chapter5.item30; -// Generic singleton factory staticfactory - Pages 131-132 - import java.util.function.UnaryOperator; -// Generic singleton factory pattern (Page 136) +// Generic singleton factory pattern (Page 136-7) public class GenericSingletonFactory { // Generic singleton factory pattern private static UnaryOperator IDENTITY_FN = (t) -> t; diff --git a/src/effectivejava/chapter5/item30/RecursiveTypeBound.java b/src/effectivejava/chapter5/item30/RecursiveTypeBound.java index 0b9e97b1..e3419dfc 100644 --- a/src/effectivejava/chapter5/item30/RecursiveTypeBound.java +++ b/src/effectivejava/chapter5/item30/RecursiveTypeBound.java @@ -1,7 +1,7 @@ package effectivejava.chapter5.item30; import java.util.*; -// Using a recursive type bound to express mutual comparability - Pages 136-137 +// Using a recursive type bound to express mutual comparability (Pages 137-8) public class RecursiveTypeBound { // Returns max value in a collection - uses recursive type bound public static > E max(Collection c) { diff --git a/src/effectivejava/chapter5/item30/Union.java b/src/effectivejava/chapter5/item30/Union.java index 47f595fc..5ecb202f 100644 --- a/src/effectivejava/chapter5/item30/Union.java +++ b/src/effectivejava/chapter5/item30/Union.java @@ -1,7 +1,7 @@ package effectivejava.chapter5.item30; import java.util.*; -// Generic union method and program to exercise it - pages 135-6 +// Generic union method and program to exercise it (Pages 135-6) public class Union { // Generic method diff --git a/src/effectivejava/chapter5/item32/Chooser.java b/src/effectivejava/chapter5/item31/Chooser.java similarity index 86% rename from src/effectivejava/chapter5/item32/Chooser.java rename to src/effectivejava/chapter5/item31/Chooser.java index fe3e2aed..bb8443d0 100644 --- a/src/effectivejava/chapter5/item32/Chooser.java +++ b/src/effectivejava/chapter5/item31/Chooser.java @@ -1,10 +1,11 @@ -package effectivejava.chapter5.item32; +package effectivejava.chapter5.item31; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Random; +// Wildcard type for parameter that serves as an T producer (page 141) public class Chooser { private final List choiceList; private final Random rnd = new Random(); diff --git a/src/effectivejava/chapter5/item32/EmptyStackException.java b/src/effectivejava/chapter5/item31/EmptyStackException.java similarity index 61% rename from src/effectivejava/chapter5/item32/EmptyStackException.java rename to src/effectivejava/chapter5/item31/EmptyStackException.java index 7af3c4c2..d5a8219b 100644 --- a/src/effectivejava/chapter5/item32/EmptyStackException.java +++ b/src/effectivejava/chapter5/item31/EmptyStackException.java @@ -1,4 +1,4 @@ -package effectivejava.chapter5.item32; +package effectivejava.chapter5.item31; public class EmptyStackException extends RuntimeException { } diff --git a/src/effectivejava/chapter5/item32/RecursiveTypeBound.java b/src/effectivejava/chapter5/item31/RecursiveTypeBound.java similarity index 84% rename from src/effectivejava/chapter5/item32/RecursiveTypeBound.java rename to src/effectivejava/chapter5/item31/RecursiveTypeBound.java index 7870961b..d50aa1cf 100644 --- a/src/effectivejava/chapter5/item32/RecursiveTypeBound.java +++ b/src/effectivejava/chapter5/item31/RecursiveTypeBound.java @@ -1,7 +1,7 @@ -package effectivejava.chapter5.item32; +package effectivejava.chapter5.item31; import java.util.*; -// Using a recursive type bound with wildcards - Page 138-139 +// Using a recursive type bound with wildcards (Page 143) public class RecursiveTypeBound { public static > E max( List list) { diff --git a/src/effectivejava/chapter5/item32/Stack.java b/src/effectivejava/chapter5/item31/Stack.java similarity index 89% rename from src/effectivejava/chapter5/item32/Stack.java rename to src/effectivejava/chapter5/item31/Stack.java index 7bc47d6b..a5abe59d 100644 --- a/src/effectivejava/chapter5/item32/Stack.java +++ b/src/effectivejava/chapter5/item31/Stack.java @@ -1,7 +1,7 @@ -package effectivejava.chapter5.item32; +package effectivejava.chapter5.item31; import java.util.*; -// Generic stack with bulk methods using wildcard types - Pages 138-140 +// Generic stack with bulk methods using wildcard types (Pages 139-41) public class Stack { private E[] elements; private int size = 0; @@ -63,11 +63,11 @@ public void popAll(Collection dst) { // Little program to exercise our generic Stack public static void main(String[] args) { - Stack numberStack = new Stack(); + Stack numberStack = new Stack<>(); Iterable integers = Arrays.asList(3, 1, 4, 1, 5, 9); numberStack.pushAll(integers); - Collection objects = new ArrayList(); + Collection objects = new ArrayList<>(); numberStack.popAll(objects); System.out.println(objects); diff --git a/src/effectivejava/chapter5/item32/Swap.java b/src/effectivejava/chapter5/item31/Swap.java similarity index 75% rename from src/effectivejava/chapter5/item32/Swap.java rename to src/effectivejava/chapter5/item31/Swap.java index 171d5cbc..776f886f 100644 --- a/src/effectivejava/chapter5/item32/Swap.java +++ b/src/effectivejava/chapter5/item31/Swap.java @@ -1,13 +1,13 @@ -package effectivejava.chapter5.item32; +package effectivejava.chapter5.item31; import java.util.*; -// Private helper staticfactory for wildcard capture - Pages 139-140 +// Private helper method for wildcard capture (Page 145) public class Swap { public static void swap(List list, int i, int j) { swapHelper(list, i, j); } - // Private helper staticfactory for wildcard capture + // Private helper method for wildcard capture private static void swapHelper(List list, int i, int j) { list.set(i, list.set(j, list.get(i))); } diff --git a/src/effectivejava/chapter5/item32/Union.java b/src/effectivejava/chapter5/item31/Union.java similarity index 74% rename from src/effectivejava/chapter5/item32/Union.java rename to src/effectivejava/chapter5/item31/Union.java index 79fb4009..71cc58b8 100644 --- a/src/effectivejava/chapter5/item32/Union.java +++ b/src/effectivejava/chapter5/item31/Union.java @@ -1,9 +1,8 @@ -package effectivejava.chapter5.item32; +package effectivejava.chapter5.item31; import java.util.*; -// Generic union staticfactory with wildcard types - Pages 137-138 +// Generic union method with wildcard types for enhanced flexibility (Pages 142-3) public class Union { - public static Set union(Set s1, Set s2) { Set result = new HashSet(s1); @@ -25,6 +24,9 @@ public static void main(String[] args) { Set numbers = union(integers, doubles); +// // Explicit type parameter - required prior to Java 8 +// Set numbers = Union.union(integers, doubles); + System.out.println(numbers); } } diff --git a/src/effectivejava/chapter5/item32/Dangerous.java b/src/effectivejava/chapter5/item32/Dangerous.java new file mode 100644 index 00000000..fdd1a499 --- /dev/null +++ b/src/effectivejava/chapter5/item32/Dangerous.java @@ -0,0 +1,18 @@ +package effectivejava.chapter5.item32; + +import java.util.List; + +// It is unsafe to store a value in a generic varargs array parameter (Page 146) +public class Dangerous { + // Mixing generics and varargs can violate type safety! + static void dangerous(List... stringLists) { + List intList = List.of(42); + Object[] objects = stringLists; + objects[0] = intList; // Heap pollution + String s = stringLists[0].get(0); // ClassCastException + } + + public static void main(String[] args) { + dangerous(List.of("There be dragons!")); + } +} diff --git a/src/effectivejava/chapter5/item32/FlattenWithList.java b/src/effectivejava/chapter5/item32/FlattenWithList.java new file mode 100644 index 00000000..b9cbaa71 --- /dev/null +++ b/src/effectivejava/chapter5/item32/FlattenWithList.java @@ -0,0 +1,20 @@ +package effectivejava.chapter5.item32; + +import java.util.ArrayList; +import java.util.List; + +// List as a typesafe alternative to a generic varargs parameter (page 149) +public class FlattenWithList { + static List flatten(List> lists) { + List result = new ArrayList<>(); + for (List list : lists) + result.addAll(list); + return result; + } + + public static void main(String[] args) { + List flatList = flatten(List.of( + List.of(1, 2), List.of(3, 4, 5), List.of(6,7))); + System.out.println(flatList); + } +} diff --git a/src/effectivejava/chapter5/item32/FlattenWithVarargs.java b/src/effectivejava/chapter5/item32/FlattenWithVarargs.java new file mode 100644 index 00000000..e33f4472 --- /dev/null +++ b/src/effectivejava/chapter5/item32/FlattenWithVarargs.java @@ -0,0 +1,21 @@ +package effectivejava.chapter5.item32; + +import java.util.ArrayList; +import java.util.List; + +// Safe method with a generic varargs parameter (page 149) +public class FlattenWithVarargs { + @SafeVarargs + static List flatten(List... lists) { + List result = new ArrayList<>(); + for (List list : lists) + result.addAll(list); + return result; + } + + public static void main(String[] args) { + List flatList = flatten( + List.of(1, 2), List.of(3, 4, 5), List.of(6,7)); + System.out.println(flatList); + } +} diff --git a/src/effectivejava/chapter5/item32/Function.java b/src/effectivejava/chapter5/item32/Function.java deleted file mode 100644 index a75bb0ad..00000000 --- a/src/effectivejava/chapter5/item32/Function.java +++ /dev/null @@ -1,6 +0,0 @@ -package effectivejava.chapter5.item32; - -// Generic Function interface - Page 122 -interface Function { - T apply(T arg1, T arg2); -} diff --git a/src/effectivejava/chapter5/item32/PickTwo.java b/src/effectivejava/chapter5/item32/PickTwo.java new file mode 100644 index 00000000..297bea62 --- /dev/null +++ b/src/effectivejava/chapter5/item32/PickTwo.java @@ -0,0 +1,26 @@ +package effectivejava.chapter5.item32; + +import java.util.Arrays; +import java.util.concurrent.ThreadLocalRandom; + +// Subtle heap pollution (Pages 147-8) +public class PickTwo { + // UNSAFE - Exposes a reference to its generic parameter array! + static T[] toArray(T... args) { + return args; + } + + static T[] pickTwo(T a, T b, T c) { + switch(ThreadLocalRandom.current().nextInt(3)) { + case 0: return toArray(a, b); + case 1: return toArray(a, c); + case 2: return toArray(b, c); + } + throw new AssertionError(); // Can't get here + } + + public static void main(String[] args) { + String[] attributes = pickTwo("Good", "Fast", "Cheap"); + System.out.println(Arrays.toString(attributes)); + } +} diff --git a/src/effectivejava/chapter5/item32/Reduction.java b/src/effectivejava/chapter5/item32/Reduction.java deleted file mode 100644 index bb1bb9d9..00000000 --- a/src/effectivejava/chapter5/item32/Reduction.java +++ /dev/null @@ -1,36 +0,0 @@ -package effectivejava.chapter5.item32; -import java.util.*; - -// List-based generic reduction with wildcard type - Page 136 -public class Reduction { - // Wildcard type for parameter that serves as an E producer - static E reduce(List list, Function f, - E initVal) { - List snapshot; - synchronized(list) { - snapshot = new ArrayList(list); - } - E result = initVal; - for (E e : snapshot) - result = f.apply(result, e); - return result; - } - - private static final Function MAX = new Function(){ - public Number apply(Number n1, Number n2) { - return Double.compare(n1.doubleValue(), n2.doubleValue()) > 0 ? - n1 : n2; - } - }; - - public static void main(String[] args) { - // We can use a Number functionto reduce a list of Integer or Double - List intList = Arrays.asList( - 2, 7, 1, 8, 2, 8, 1, 8, 2, 8); - System.out.println(reduce(intList, MAX, Integer.MIN_VALUE)); - - List doubleList = Arrays.asList( - 2.718281828, 3.141592654, 1.61803399); - System.out.println(reduce(doubleList, MAX, Double.NEGATIVE_INFINITY)); - } -} diff --git a/src/effectivejava/chapter5/item32/SafePickTwo.java b/src/effectivejava/chapter5/item32/SafePickTwo.java new file mode 100644 index 00000000..b8d864bf --- /dev/null +++ b/src/effectivejava/chapter5/item32/SafePickTwo.java @@ -0,0 +1,22 @@ +package effectivejava.chapter5.item32; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +// Safe version of PickTwo using lists instead of arrays (Page 150) +public class SafePickTwo { + static List pickTwo(T a, T b, T c) { + switch(ThreadLocalRandom.current().nextInt(3)) { + case 0: return List.of(a, b); + case 1: return List.of(a, c); + case 2: return List.of(b, c); + } + throw new AssertionError(); + } + + public static void main(String[] args) { + List attributes = pickTwo("Good", "Fast", "Cheap"); + System.out.println(attributes); + } +} diff --git a/src/effectivejava/chapter5/item33/Favorites.java b/src/effectivejava/chapter5/item33/Favorites.java index 1d58204f..4e3385f7 100644 --- a/src/effectivejava/chapter5/item33/Favorites.java +++ b/src/effectivejava/chapter5/item33/Favorites.java @@ -1,34 +1,32 @@ package effectivejava.chapter5.item33; import java.util.*; -// Typesafe heterogeneous container - Pages 142-145 +// Typesafe heterogeneous container pattern (Pages 151-4) public class Favorites { - // Typesafe heterogeneous container pattern - implementation - private Map, Object> favorites = - new HashMap, Object>(); + private Map, Object> favorites = new HashMap<>(); public void putFavorite(Class type, T instance) { - if (type == null) - throw new NullPointerException("LifeCycle is null"); - favorites.put(type, instance); + favorites.put(Objects.requireNonNull(type), instance); } public T getFavorite(Class type) { return type.cast(favorites.get(type)); } +// // Achieving runtime type safety with a dynamic cast +// public void putFavorite(Class type, T instance) { +// favorites.put(Objects.requireNonNull(type), type.cast(instance)); +// } - // Typesafe heterogeneous container pattern - client public static void main(String[] args) { Favorites f = new Favorites(); f.putFavorite(String.class, "Java"); f.putFavorite(Integer.class, 0xcafebabe); f.putFavorite(Class.class, Favorites.class); - String favoriteString = f.getFavorite(String.class); int favoriteInteger = f.getFavorite(Integer.class); Class favoriteClass = f.getFavorite(Class.class); System.out.printf("%s %x %s%n", favoriteString, - favoriteInteger, favoriteClass.getName()); + favoriteInteger, favoriteClass.getName()); } } \ No newline at end of file diff --git a/src/effectivejava/chapter5/item33/PrintAnnotation.java b/src/effectivejava/chapter5/item33/PrintAnnotation.java index 80134843..bbd3d13c 100644 --- a/src/effectivejava/chapter5/item33/PrintAnnotation.java +++ b/src/effectivejava/chapter5/item33/PrintAnnotation.java @@ -2,9 +2,8 @@ import java.lang.annotation.*; import java.lang.reflect.*; -// Use of asSubclass to safely cast to a bounded type token - Page 146 +// Use of asSubclass to safely cast to a bounded type token (Page 155) public class PrintAnnotation { - // Use of asSubclass to safely cast to a bounded type token static Annotation getAnnotation(AnnotatedElement element, String annotationTypeName) { Class annotationType = null; // Unbounded type token @@ -14,7 +13,7 @@ static Annotation getAnnotation(AnnotatedElement element, throw new IllegalArgumentException(ex); } return element.getAnnotation( - annotationType.asSubclass(Annotation.class)); + annotationType.asSubclass(Annotation.class)); } // Test program to print named annotation of named class diff --git a/src/effectivejava/chapter6/item34/Inverse.java b/src/effectivejava/chapter6/item34/Inverse.java new file mode 100644 index 00000000..cced1080 --- /dev/null +++ b/src/effectivejava/chapter6/item34/Inverse.java @@ -0,0 +1,25 @@ +package effectivejava.chapter6.item34; + +// Switch on an enum to simulate a missing method (Page 167) +public class Inverse { + public static Operation inverse(Operation op) { + switch(op) { + case PLUS: return Operation.MINUS; + case MINUS: return Operation.PLUS; + case TIMES: return Operation.DIVIDE; + case DIVIDE: return Operation.TIMES; + + default: throw new AssertionError("Unknown op: " + op); + } + } + + public static void main(String[] args) { + double x = Double.parseDouble(args[0]); + double y = Double.parseDouble(args[1]); + for (Operation op : Operation.values()) { + Operation invOp = inverse(op); + System.out.printf("%f %s %f %s %f = %f%n", + x, op, y, invOp, y, invOp.apply(op.apply(x, y), y)); + } + } +} diff --git a/src/effectivejava/chapter6/item34/Operation.java b/src/effectivejava/chapter6/item34/Operation.java index 6b88fc3a..ba89c8f9 100644 --- a/src/effectivejava/chapter6/item34/Operation.java +++ b/src/effectivejava/chapter6/item34/Operation.java @@ -4,7 +4,7 @@ import static java.util.stream.Collectors.toMap; -// Enum type with constant-specific class bodies and data (Page 161) +// Enum type with constant-specific class bodies and data (Pages 163-4) public enum Operation { PLUS("+") { public double apply(double x, double y) { return x + y; } @@ -27,7 +27,7 @@ public enum Operation { public abstract double apply(double x, double y); - // Implementing a fromString method on an enum type + // Implementing a fromString method on an enum type (Page 164) private static final Map stringToEnum = Stream.of(values()).collect( toMap(Object::toString, e -> e)); diff --git a/src/effectivejava/chapter6/item34/PayrollDay.java b/src/effectivejava/chapter6/item34/PayrollDay.java index 0dc831ab..54a89c12 100644 --- a/src/effectivejava/chapter6/item34/PayrollDay.java +++ b/src/effectivejava/chapter6/item34/PayrollDay.java @@ -1,21 +1,23 @@ package effectivejava.chapter6.item34; -// The strategy enum pattern +import static effectivejava.chapter6.item34.PayrollDay.PayType.*; + +// The strategy enum pattern (Page 166) enum PayrollDay { - MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, - SATURDAY(PayType.WEEKEND), SUNDAY(PayType.WEEKEND); + MONDAY(WEEKDAY), TUESDAY(WEEKDAY), WEDNESDAY(WEEKDAY), + THURSDAY(WEEKDAY), FRIDAY(WEEKDAY), + SATURDAY(WEEKEND), SUNDAY(WEEKEND); private final PayType payType; PayrollDay(PayType payType) { this.payType = payType; } - PayrollDay() { this(PayType.WEEKDAY); } // Default int pay(int minutesWorked, int payRate) { return payType.pay(minutesWorked, payRate); } // The strategy enum type - private enum PayType { + enum PayType { WEEKDAY { int overtimePay(int minsWorked, int payRate) { return minsWorked <= MINS_PER_SHIFT ? 0 : @@ -36,4 +38,9 @@ int pay(int minsWorked, int payRate) { return basePay + overtimePay(minsWorked, payRate); } } + + public static void main(String[] args) { + for (PayrollDay day : values()) + System.out.printf("%-10s%d%n", day, day.pay(8 * 60, 1)); + } } diff --git a/src/effectivejava/chapter6/item34/Planet.java b/src/effectivejava/chapter6/item34/Planet.java index 833cf8c8..af74c405 100644 --- a/src/effectivejava/chapter6/item34/Planet.java +++ b/src/effectivejava/chapter6/item34/Planet.java @@ -1,6 +1,6 @@ package effectivejava.chapter6.item34; -// Enum type with data and behavior (157-158) +// Enum type with data and behavior (159-160) public enum Planet { MERCURY(3.302e+23, 2.439e6), VENUS (4.869e+24, 6.052e6), @@ -14,6 +14,7 @@ public enum Planet { private final double mass; // In kilograms private final double radius; // In meters private final double surfaceGravity; // In m / s^2 + // Universal gravitational constant in m^3 / kg s^2 private static final double G = 6.67300E-11; diff --git a/src/effectivejava/chapter6/item34/WeightTable.java b/src/effectivejava/chapter6/item34/WeightTable.java index 8569a739..948c2e37 100644 --- a/src/effectivejava/chapter6/item34/WeightTable.java +++ b/src/effectivejava/chapter6/item34/WeightTable.java @@ -1,6 +1,6 @@ package effectivejava.chapter6.item34; -// Takes earth-weight and prints table of weights on all planets - Page 158 +// Takes earth-weight and prints table of weights on all planets (Page 160) public class WeightTable { public static void main(String[] args) { double earthWeight = Double.parseDouble(args[0]); diff --git a/src/effectivejava/chapter6/item35/Ensemble.java b/src/effectivejava/chapter6/item35/Ensemble.java index 3b6b1e6c..51e21a32 100644 --- a/src/effectivejava/chapter6/item35/Ensemble.java +++ b/src/effectivejava/chapter6/item35/Ensemble.java @@ -1,6 +1,6 @@ package effectivejava.chapter6.item35; -// Enum with integer data stored in an instance field (Page 166) +// Enum with integer data stored in an instance field (Page 168) public enum Ensemble { SOLO(1), DUET(2), TRIO(3), QUARTET(4), QUINTET(5), SEXTET(6), SEPTET(7), OCTET(8), DOUBLE_QUARTET(8), diff --git a/src/effectivejava/chapter6/item36/Text.java b/src/effectivejava/chapter6/item36/Text.java index b552643e..9f8aa6cd 100644 --- a/src/effectivejava/chapter6/item36/Text.java +++ b/src/effectivejava/chapter6/item36/Text.java @@ -1,16 +1,20 @@ package effectivejava.chapter6.item36; + import java.util.*; -// EnumSet - a modern replacement for bit fields (Page 168) +// EnumSet - a modern replacement for bit fields (Page 170) public class Text { - public enum Style { BOLD, ITALIC, UNDERLINE, STRIKETHROUGH } + public enum Style {BOLD, ITALIC, UNDERLINE, STRIKETHROUGH} // Any Set could be passed in, but EnumSet is clearly best - public void applyStyles(Set