diff --git a/arrays/ArrayOfGenericType.java b/arrays/ArrayOfGenericType.java index 90928f8b..394ed961 100644 --- a/arrays/ArrayOfGenericType.java +++ b/arrays/ArrayOfGenericType.java @@ -8,9 +8,9 @@ public class ArrayOfGenericType { T[] array; // OK @SuppressWarnings("unchecked") public ArrayOfGenericType(int size) { - //! array = new T[size]; // Illegal + //- array = new T[size]; // Illegal array = (T[])new Object[size]; // "unchecked" Warning } // Illegal: - //! public U[] makeArray() { return new U[10]; } + //- public U[] makeArray() { return new U[10]; } } diff --git a/arrays/ArrayOfGenerics.java b/arrays/ArrayOfGenerics.java index b48fa93a..ea82ad44 100644 --- a/arrays/ArrayOfGenerics.java +++ b/arrays/ArrayOfGenerics.java @@ -13,7 +13,7 @@ public class ArrayOfGenerics { ls = (List[])la; // "Unchecked" warning ls[0] = new ArrayList<>(); // Compile-time checking produces an error: - //! ls[1] = new ArrayList(); + //- ls[1] = new ArrayList(); // The problem: List is a subtype of Object Object[] objects = ls; // So assignment is OK diff --git a/arrays/ArrayOptions.java b/arrays/ArrayOptions.java index 11a02e1c..6906310e 100644 --- a/arrays/ArrayOptions.java +++ b/arrays/ArrayOptions.java @@ -49,8 +49,8 @@ public class ArrayOptions { g[i] = i*i; int[] h = { 11, 47, 93 }; - // Compile error: variable e not initialized: - //!print("e.length = " + e.length); + // Compile error: variable e not initialized: + //- print("e.length = " + e.length); System.out.println("f.length = " + f.length); System.out.println("g.length = " + g.length); System.out.println("h.length = " + h.length); diff --git a/collections/ArrayIsNotIterable.java b/collections/ArrayIsNotIterable.java index d22a629b..87177d44 100644 --- a/collections/ArrayIsNotIterable.java +++ b/collections/ArrayIsNotIterable.java @@ -13,7 +13,7 @@ public class ArrayIsNotIterable { test(Arrays.asList(1, 2, 3)); String[] strings = { "A", "B", "C" }; // An array works in for-in, but it's not Iterable: - //! test(strings); + //- test(strings); // You must explicitly convert it to an Iterable: test(Arrays.asList(strings)); } diff --git a/collectionsindepth/ReadOnly.java b/collectionsindepth/ReadOnly.java index 242bb80a..2f5afd74 100644 --- a/collectionsindepth/ReadOnly.java +++ b/collectionsindepth/ReadOnly.java @@ -14,18 +14,18 @@ public class ReadOnly { Collections.unmodifiableCollection( new ArrayList<>(data)); System.out.println(c); // Reading is OK - //! c.add("one"); // Can't change it + //- c.add("one"); // Can't change it List a = Collections.unmodifiableList( new ArrayList<>(data)); ListIterator lit = a.listIterator(); System.out.println(lit.next()); // Reading is OK - //! lit.add("one"); // Can't change it + //- lit.add("one"); // Can't change it Set s = Collections.unmodifiableSet( new HashSet<>(data)); System.out.println(s); // Reading is OK - //! s.add("one"); // Can't change it + //- s.add("one"); // Can't change it // For a SortedSet: Set ss = Collections.unmodifiableSortedSet( @@ -34,7 +34,7 @@ public class ReadOnly { Map m = Collections.unmodifiableMap( new HashMap<>(Countries.capitals(6))); System.out.println(m); // Reading is OK - //! m.put("Ralph", "Howdy!"); + //- m.put("Ralph", "Howdy!"); // For a SortedMap: Map sm = diff --git a/concurrency/ResponsiveUI.java b/concurrency/ResponsiveUI.java index 254f9f90..886cb194 100644 --- a/concurrency/ResponsiveUI.java +++ b/concurrency/ResponsiveUI.java @@ -27,7 +27,7 @@ public class ResponsiveUI extends Thread { } } public static void main(String[] args) throws Exception { - //! new UnresponsiveUI(); // Must kill this process + //- new UnresponsiveUI(); // Must kill this process new ResponsiveUI(); System.in.read(); System.out.println(d); // Shows progress diff --git a/control/BreakAndContinue.java b/control/BreakAndContinue.java index 65b2d01f..ed3d46a7 100644 --- a/control/BreakAndContinue.java +++ b/control/BreakAndContinue.java @@ -7,14 +7,14 @@ import static onjava.Range.*; public class BreakAndContinue { public static void main(String[] args) { - for(int i = 0; i < 100; i++) { + for(int i = 0; i < 100; i++) { // (1) if(i == 74) break; // Out of for loop if(i % 9 != 0) continue; // Next iteration System.out.print(i + " "); } System.out.println(); // Using for-in: - for(int i : range(100)) { + for(int i : range(100)) { // (2) if(i == 74) break; // Out of for loop if(i % 9 != 0) continue; // Next iteration System.out.print(i + " "); @@ -22,7 +22,7 @@ public class BreakAndContinue { System.out.println(); int i = 0; // An "infinite loop": - while(true) { + while(true) { // (3) i++; int j = i * 27; if(j == 1269) break; // Out of loop diff --git a/control/IfElse.java b/control/IfElse.java index 70480877..2aaa3bb1 100644 --- a/control/IfElse.java +++ b/control/IfElse.java @@ -8,7 +8,7 @@ public class IfElse { static void test(int testval, int target) { if(testval > target) result = +1; - else if(testval < target) + else if(testval < target) // (1) result = -1; else result = 0; // Match diff --git a/control/IfElse2.java b/control/TestWithReturn.java similarity index 80% rename from control/IfElse2.java rename to control/TestWithReturn.java index 0c065d10..33c61893 100644 --- a/control/IfElse2.java +++ b/control/TestWithReturn.java @@ -1,16 +1,15 @@ -// control/IfElse2.java +// control/TestWithReturn.java // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. -public class IfElse2 { +public class TestWithReturn { static int test(int testval, int target) { if(testval > target) return +1; - else if(testval < target) + if(testval < target) return -1; - else - return 0; // Match + return 0; // Match } public static void main(String[] args) { System.out.println(test(10, 5)); diff --git a/control/TrueFalse.java b/control/TrueFalse.java new file mode 100644 index 00000000..9321ef1a --- /dev/null +++ b/control/TrueFalse.java @@ -0,0 +1,15 @@ +// control/TrueFalse.java +// (c)2016 MindView LLC: see Copyright.txt +// We make no guarantees that this code is fit for any purpose. +// Visit http://mindviewinc.com/Books/OnJava/ for more book information. + +public class TrueFalse { + public static void main(String[] args) { + System.out.println(1 == 1); + System.out.println(1 == 2); + } +} +/* Output: +true +false +*/ diff --git a/control/build.xml b/control/build.xml index 969f5f19..5b0f6b3a 100644 --- a/control/build.xml +++ b/control/build.xml @@ -13,11 +13,12 @@ - + + @@ -29,11 +30,12 @@ - + + diff --git a/exceptions/StormyInning.java b/exceptions/StormyInning.java index 9dd0e5c5..c9cbac60 100644 --- a/exceptions/StormyInning.java +++ b/exceptions/StormyInning.java @@ -37,10 +37,10 @@ class StormyInning extends Inning implements Storm { public StormyInning(String s) throws Foul, BaseballException {} // Regular methods must conform to base class: -//! void walk() throws PopFoul {} //Compile error + //- void walk() throws PopFoul {} //Compile error // Interface CANNOT add exceptions to existing // methods from the base class: -//! public void event() throws RainedOut {} + //- public void event() throws RainedOut {} // If the method doesn't already exist in the // base class, the exception is OK: @Override diff --git a/generics/ArrayOfGeneric.java b/generics/ArrayOfGeneric.java index df7240f1..70bea798 100644 --- a/generics/ArrayOfGeneric.java +++ b/generics/ArrayOfGeneric.java @@ -9,14 +9,14 @@ public class ArrayOfGeneric { @SuppressWarnings("unchecked") public static void main(String[] args) { // Compiles; produces ClassCastException: - //! gia = (Generic[])new Object[SIZE]; + //- gia = (Generic[])new Object[SIZE]; // Runtime type is the raw (erased) type: gia = (Generic[])new Generic[SIZE]; System.out.println(gia.getClass().getSimpleName()); gia[0] = new Generic<>(); - //! gia[1] = new Object(); // Compile-time error + //- gia[1] = new Object(); // Compile-time error // Discovers type mismatch at compile time: - //! gia[2] = new Generic(); + //- gia[2] = new Generic(); } } /* Output: diff --git a/generics/GenericArray.java b/generics/GenericArray.java index 7e326c9b..cc469d93 100644 --- a/generics/GenericArray.java +++ b/generics/GenericArray.java @@ -18,7 +18,7 @@ public class GenericArray { public static void main(String[] args) { GenericArray gai = new GenericArray<>(10); // This causes a ClassCastException: - //! Integer[] ia = gai.rep(); + //- Integer[] ia = gai.rep(); // This is OK: Object[] oa = gai.rep(); } diff --git a/generics/decorator/Decoration.java b/generics/decorator/Decoration.java index 6f4c5f47..f54d7f41 100644 --- a/generics/decorator/Decoration.java +++ b/generics/decorator/Decoration.java @@ -41,10 +41,10 @@ public class Decoration { TimeStamped t = new TimeStamped(new Basic()); TimeStamped t2 = new TimeStamped( new SerialNumbered(new Basic())); - //! t2.getSerialNumber(); // Not available + //- t2.getSerialNumber(); // Not available SerialNumbered s = new SerialNumbered(new Basic()); SerialNumbered s2 = new SerialNumbered( new TimeStamped(new Basic())); - //! s2.getStamp(); // Not available + //- s2.getStamp(); // Not available } } diff --git a/hiding/ChocolateChip.java b/hiding/ChocolateChip.java index e7973c27..07066137 100644 --- a/hiding/ChocolateChip.java +++ b/hiding/ChocolateChip.java @@ -10,7 +10,7 @@ public class ChocolateChip extends Cookie { System.out.println("ChocolateChip constructor"); } public void chomp() { - //! bite(); // Can't access bite + //- bite(); // Can't access bite } public static void main(String[] args) { ChocolateChip x = new ChocolateChip(); diff --git a/hiding/Dinner.java b/hiding/Dinner.java index cad6d17d..7c653ce7 100644 --- a/hiding/Dinner.java +++ b/hiding/Dinner.java @@ -8,7 +8,7 @@ import hiding.dessert.*; public class Dinner { public static void main(String[] args) { Cookie x = new Cookie(); - //! x.bite(); // Can't access + //- x.bite(); // Can't access } } /* Output: diff --git a/hiding/IceCream.java b/hiding/IceCream.java index ae05019b..d6eacdb8 100644 --- a/hiding/IceCream.java +++ b/hiding/IceCream.java @@ -13,7 +13,7 @@ class Sundae { public class IceCream { public static void main(String[] args) { - //! Sundae x = new Sundae(); + //- Sundae x = new Sundae(); Sundae x = Sundae.makeASundae(); } } diff --git a/hiding/Lunch.java b/hiding/Lunch.java index 10c94712..e470fcc8 100644 --- a/hiding/Lunch.java +++ b/hiding/Lunch.java @@ -25,7 +25,7 @@ class Soup2 { public class Lunch { void testPrivate() { // Can't do this! Private constructor: - //! Soup1 soup = new Soup1(); + //- Soup1 soup = new Soup1(); } void testStatic() { Soup1 soup = Soup1.makeSoup(); diff --git a/housekeeping/Demotion.java b/housekeeping/Demotion.java index ffd9f3b2..cd103a8b 100644 --- a/housekeeping/Demotion.java +++ b/housekeeping/Demotion.java @@ -2,49 +2,27 @@ // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. -// Demotion of primitives and overloading. +// Demotion of primitives. public class Demotion { - void f1(char x) { System.out.println("f1(char)"); } - void f1(byte x) { System.out.println("f1(byte)"); } - void f1(short x) { System.out.println("f1(short)"); } - void f1(int x) { System.out.println("f1(int)"); } - void f1(long x) { System.out.println("f1(long)"); } - void f1(float x) { System.out.println("f1(float)"); } void f1(double x) { System.out.println("f1(double)"); } - - void f2(char x) { System.out.println("f2(char)"); } - void f2(byte x) { System.out.println("f2(byte)"); } - void f2(short x) { System.out.println("f2(short)"); } - void f2(int x) { System.out.println("f2(int)"); } - void f2(long x) { System.out.println("f2(long)"); } void f2(float x) { System.out.println("f2(float)"); } - - void f3(char x) { System.out.println("f3(char)"); } - void f3(byte x) { System.out.println("f3(byte)"); } - void f3(short x) { System.out.println("f3(short)"); } - void f3(int x) { System.out.println("f3(int)"); } void f3(long x) { System.out.println("f3(long)"); } - - void f4(char x) { System.out.println("f4(char)"); } - void f4(byte x) { System.out.println("f4(byte)"); } - void f4(short x) { System.out.println("f4(short)"); } void f4(int x) { System.out.println("f4(int)"); } - - void f5(char x) { System.out.println("f5(char)"); } - void f5(byte x) { System.out.println("f5(byte)"); } void f5(short x) { System.out.println("f5(short)"); } - - void f6(char x) { System.out.println("f6(char)"); } void f6(byte x) { System.out.println("f6(byte)"); } - void f7(char x) { System.out.println("f7(char)"); } void testDouble() { double x = 0; System.out.println("double argument:"); - f1(x);f2((float)x);f3((long)x);f4((int)x); - f5((short)x);f6((byte)x);f7((char)x); + f1(x); + f2((float)x); + f3((long)x); + f4((int)x); + f5((short)x); + f6((byte)x); + f7((char)x); } public static void main(String[] args) { Demotion p = new Demotion(); diff --git a/housekeeping/Flower.java b/housekeeping/Flower.java index a214cef6..adf106ca 100644 --- a/housekeeping/Flower.java +++ b/housekeeping/Flower.java @@ -20,7 +20,7 @@ public class Flower { } Flower(String s, int petals) { this(petals); -//! this(s); // Can't call two! + //- this(s); // Can't call two! this.s = s; // Another use of "this" System.out.println("String & int args"); } @@ -29,7 +29,7 @@ public class Flower { System.out.println("no-arg constructor"); } void printPetalCount() { -//! this(11); // Not inside non-constructor! + //- this(11); // Not inside non-constructor! System.out.println( "petalCount = " + petalCount + " s = "+ s); } diff --git a/housekeeping/InitialValues.java b/housekeeping/InitialValues.java index 9ee4a2b1..41b48da0 100644 --- a/housekeeping/InitialValues.java +++ b/housekeeping/InitialValues.java @@ -15,34 +15,30 @@ public class InitialValues { double d; InitialValues reference; void printInitialValues() { - System.out.println("Data type Initial value"); - System.out.println("boolean " + t); - System.out.println("char [" + c + "]"); - System.out.println("byte " + b); - System.out.println("short " + s); - System.out.println("int " + i); - System.out.println("long " + l); - System.out.println("float " + f); - System.out.println("double " + d); - System.out.println("reference " + reference); + System.out.println("Data type Initial value"); + System.out.println("boolean " + t); + System.out.println("char [" + c + "]"); + System.out.println("byte " + b); + System.out.println("short " + s); + System.out.println("int " + i); + System.out.println("long " + l); + System.out.println("float " + f); + System.out.println("double " + d); + System.out.println("reference " + reference); } public static void main(String[] args) { - InitialValues iv = new InitialValues(); - iv.printInitialValues(); - /* You can also say: new InitialValues().printInitialValues(); - */ } } /* Output: -Data type Initial value -boolean false -char [NUL] -byte 0 -short 0 -int 0 -long 0 -float 0.0 -double 0.0 -reference null +Data type Initial value +boolean false +char [NUL] +byte 0 +short 0 +int 0 +long 0 +float 0.0 +double 0.0 +reference null */ diff --git a/housekeeping/MethodInit3.java b/housekeeping/MethodInit3.java index 2c407ac1..5a39920a 100644 --- a/housekeeping/MethodInit3.java +++ b/housekeeping/MethodInit3.java @@ -3,7 +3,7 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. public class MethodInit3 { - //! int j = g(i); // Illegal forward reference + //- int j = g(i); // Illegal forward reference int i = f(); int f() { return 11; } int g(int n) { return n * 10; } diff --git a/housekeeping/Mugs.java b/housekeeping/Mugs.java index 0c1010d2..3c08197a 100644 --- a/housekeeping/Mugs.java +++ b/housekeeping/Mugs.java @@ -2,7 +2,7 @@ // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. -// Java "Instance Initialization." +// Instance initialization. class Mug { Mug(int marker) { @@ -16,7 +16,7 @@ class Mug { public class Mugs { Mug mug1; Mug mug2; - { + { // (1) mug1 = new Mug(1); mug2 = new Mug(2); System.out.println("mug1 & mug2 initialized"); diff --git a/housekeeping/NoSynthesis.java b/housekeeping/NoSynthesis.java index 1d44518c..ee5c1f1e 100644 --- a/housekeeping/NoSynthesis.java +++ b/housekeeping/NoSynthesis.java @@ -10,7 +10,7 @@ class Bird2 { public class NoSynthesis { public static void main(String[] args) { - //! Bird2 b = new Bird2(); // No default + //- Bird2 b = new Bird2(); // No default Bird2 b2 = new Bird2(1); Bird2 b3 = new Bird2(1.0); } diff --git a/housekeeping/OverloadingVarargs.java b/housekeeping/OverloadingVarargs.java index 34bfc184..a9757c97 100644 --- a/housekeeping/OverloadingVarargs.java +++ b/housekeeping/OverloadingVarargs.java @@ -25,7 +25,7 @@ public class OverloadingVarargs { f(2, 1); f(0); f(0L); - //! f(); // Won't compile -- ambiguous + //- f(); // Won't compile -- ambiguous } } /* Output: diff --git a/innerclasses/InheritInner.java b/innerclasses/InheritInner.java index 61f9586c..fa48df17 100644 --- a/innerclasses/InheritInner.java +++ b/innerclasses/InheritInner.java @@ -9,7 +9,7 @@ class WithInner { } public class InheritInner extends WithInner.Inner { - //! InheritInner() {} // Won't compile + //- InheritInner() {} // Won't compile InheritInner(WithInner wi) { wi.super(); } diff --git a/innerclasses/Parcel6.java b/innerclasses/Parcel6.java index 5f077f7f..87fc0e68 100644 --- a/innerclasses/Parcel6.java +++ b/innerclasses/Parcel6.java @@ -18,7 +18,7 @@ public class Parcel6 { String s = ts.getSlip(); } // Can't use it here! Out of scope: - //! TrackingSlip ts = new TrackingSlip("x"); + //- TrackingSlip ts = new TrackingSlip("x"); } public void track() { internalTracking(true); } public static void main(String[] args) { diff --git a/innerclasses/TestParcel.java b/innerclasses/TestParcel.java index 5f2c3300..c87fcd1a 100644 --- a/innerclasses/TestParcel.java +++ b/innerclasses/TestParcel.java @@ -31,6 +31,6 @@ public class TestParcel { Contents c = p.contents(); Destination d = p.destination("Tasmania"); // Illegal -- can't access private class: - //! Parcel4.PContents pc = p.new PContents(); + //- Parcel4.PContents pc = p.new PContents(); } } diff --git a/interfaces/InterfaceCollision.java b/interfaces/InterfaceCollision.java index ac81ac9e..4d761b9b 100644 --- a/interfaces/InterfaceCollision.java +++ b/interfaces/InterfaceCollision.java @@ -27,5 +27,5 @@ class C4 extends C implements I3 { } // Methods differ only by return type: -//! class C5 extends C implements I1 {} -//! interface I4 extends I1, I3 {} +//- class C5 extends C implements I1 {} +//- interface I4 extends I1, I3 {} diff --git a/interfaces/nesting/NestingInterfaces.java b/interfaces/nesting/NestingInterfaces.java index 0eb0d484..555e6bf3 100644 --- a/interfaces/nesting/NestingInterfaces.java +++ b/interfaces/nesting/NestingInterfaces.java @@ -56,7 +56,7 @@ interface E { } void g(); // Cannot be private within an interface: - //! private interface I {} + //- private interface I {} } public class NestingInterfaces { @@ -70,9 +70,9 @@ public class NestingInterfaces { } // Cannot implement a private interface except // within that interface's defining class: - //! class DImp implements A.D { - //! public void f() {} - //! } + //- class DImp implements A.D { + //- public void f() {} + //- } class EImp implements E { @Override public void g() {} @@ -92,11 +92,11 @@ public class NestingInterfaces { public static void main(String[] args) { A a = new A(); // Can't access A.D: - //! A.D ad = a.getD(); + //- A.D ad = a.getD(); // Doesn't return anything but A.D: - //! A.DImp2 di2 = a.getD(); + //- A.DImp2 di2 = a.getD(); // Cannot access a member of the interface: - //! a.getD().f(); + //- a.getD().f(); // Only another A can do anything with getD(): A a2 = new A(); a2.receiveD(a.getD()); diff --git a/operators/AllOps.java b/operators/AllOps.java index af7f01e8..bbd3c0d8 100644 --- a/operators/AllOps.java +++ b/operators/AllOps.java @@ -10,53 +10,53 @@ public class AllOps { void f(boolean b) {} void boolTest(boolean x, boolean y) { // Arithmetic operators: - //! x = x * y; - //! x = x / y; - //! x = x % y; - //! x = x + y; - //! x = x - y; - //! x++; - //! x--; - //! x = +y; - //! x = -y; + //- x = x * y; + //- x = x / y; + //- x = x % y; + //- x = x + y; + //- x = x - y; + //- x++; + //- x--; + //- x = +y; + //- x = -y; // Relational and logical: - //! f(x > y); - //! f(x >= y); - //! f(x < y); - //! f(x <= y); + //- f(x > y); + //- f(x >= y); + //- f(x < y); + //- f(x <= y); f(x == y); f(x != y); f(!y); x = x && y; x = x || y; // Bitwise operators: - //! x = ~y; + //- x = ~y; x = x & y; x = x | y; x = x ^ y; - //! x = x << 1; - //! x = x >> 1; - //! x = x >>> 1; + //- x = x << 1; + //- x = x >> 1; + //- x = x >>> 1; // Compound assignment: - //! x += y; - //! x -= y; - //! x *= y; - //! x /= y; - //! x %= y; - //! x <<= 1; - //! x >>= 1; - //! x >>>= 1; + //- x += y; + //- x -= y; + //- x *= y; + //- x /= y; + //- x %= y; + //- x <<= 1; + //- x >>= 1; + //- x >>>= 1; x &= y; x ^= y; x |= y; // Casting: - //! char c = (char)x; - //! byte b = (byte)x; - //! short s = (short)x; - //! int i = (int)x; - //! long l = (long)x; - //! float f = (float)x; - //! double d = (double)x; + //- char c = (char)x; + //- byte b = (byte)x; + //- short s = (short)x; + //- int i = (int)x; + //- long l = (long)x; + //- float f = (float)x; + //- double d = (double)x; } void charTest(char x, char y) { // Arithmetic operators: @@ -76,9 +76,9 @@ public class AllOps { f(x <= y); f(x == y); f(x != y); - //! f(!x); - //! f(x && y); - //! f(x || y); + //- f(!x); + //- f(x && y); + //- f(x || y); // Bitwise operators: x= (char)~y; x = (char)(x & y); @@ -100,7 +100,7 @@ public class AllOps { x ^= y; x |= y; // Casting: - //! boolean bl = (boolean)x; + //- boolean bl = (boolean)x; byte b = (byte)x; short s = (short)x; int i = (int)x; @@ -126,9 +126,9 @@ public class AllOps { f(x <= y); f(x == y); f(x != y); - //! f(!x); - //! f(x && y); - //! f(x || y); + //- f(!x); + //- f(x && y); + //- f(x || y); // Bitwise operators: x = (byte)~y; x = (byte)(x & y); @@ -150,7 +150,7 @@ public class AllOps { x ^= y; x |= y; // Casting: - //! boolean bl = (boolean)x; + //- boolean bl = (boolean)x; char c = (char)x; short s = (short)x; int i = (int)x; @@ -176,9 +176,9 @@ public class AllOps { f(x <= y); f(x == y); f(x != y); - //! f(!x); - //! f(x && y); - //! f(x || y); + //- f(!x); + //- f(x && y); + //- f(x || y); // Bitwise operators: x = (short)~y; x = (short)(x & y); @@ -200,7 +200,7 @@ public class AllOps { x ^= y; x |= y; // Casting: - //! boolean bl = (boolean)x; + //- boolean bl = (boolean)x; char c = (char)x; byte b = (byte)x; int i = (int)x; @@ -226,9 +226,9 @@ public class AllOps { f(x <= y); f(x == y); f(x != y); - //! f(!x); - //! f(x && y); - //! f(x || y); + //- f(!x); + //- f(x && y); + //- f(x || y); // Bitwise operators: x = ~y; x = x & y; @@ -250,7 +250,7 @@ public class AllOps { x ^= y; x |= y; // Casting: - //! boolean bl = (boolean)x; + //- boolean bl = (boolean)x; char c = (char)x; byte b = (byte)x; short s = (short)x; @@ -276,9 +276,9 @@ public class AllOps { f(x <= y); f(x == y); f(x != y); - //! f(!x); - //! f(x && y); - //! f(x || y); + //- f(!x); + //- f(x && y); + //- f(x || y); // Bitwise operators: x = ~y; x = x & y; @@ -300,7 +300,7 @@ public class AllOps { x ^= y; x |= y; // Casting: - //! boolean bl = (boolean)x; + //- boolean bl = (boolean)x; char c = (char)x; byte b = (byte)x; short s = (short)x; @@ -326,31 +326,31 @@ public class AllOps { f(x <= y); f(x == y); f(x != y); - //! f(!x); - //! f(x && y); - //! f(x || y); + //- f(!x); + //- f(x && y); + //- f(x || y); // Bitwise operators: - //! x = ~y; - //! x = x & y; - //! x = x | y; - //! x = x ^ y; - //! x = x << 1; - //! x = x >> 1; - //! x = x >>> 1; + //- x = ~y; + //- x = x & y; + //- x = x | y; + //- x = x ^ y; + //- x = x << 1; + //- x = x >> 1; + //- x = x >>> 1; // Compound assignment: x += y; x -= y; x *= y; x /= y; x %= y; - //! x <<= 1; - //! x >>= 1; - //! x >>>= 1; - //! x &= y; - //! x ^= y; - //! x |= y; + //- x <<= 1; + //- x >>= 1; + //- x >>>= 1; + //- x &= y; + //- x ^= y; + //- x |= y; // Casting: - //! boolean bl = (boolean)x; + //- boolean bl = (boolean)x; char c = (char)x; byte b = (byte)x; short s = (short)x; @@ -376,31 +376,31 @@ public class AllOps { f(x <= y); f(x == y); f(x != y); - //! f(!x); - //! f(x && y); - //! f(x || y); + //- f(!x); + //- f(x && y); + //- f(x || y); // Bitwise operators: - //! x = ~y; - //! x = x & y; - //! x = x | y; - //! x = x ^ y; - //! x = x << 1; - //! x = x >> 1; - //! x = x >>> 1; + //- x = ~y; + //- x = x & y; + //- x = x | y; + //- x = x ^ y; + //- x = x << 1; + //- x = x >> 1; + //- x = x >>> 1; // Compound assignment: x += y; x -= y; x *= y; x /= y; x %= y; - //! x <<= 1; - //! x >>= 1; - //! x >>>= 1; - //! x &= y; - //! x ^= y; - //! x |= y; + //- x <<= 1; + //- x >>= 1; + //- x >>>= 1; + //- x &= y; + //- x ^= y; + //- x |= y; // Casting: - //! boolean bl = (boolean)x; + //- boolean bl = (boolean)x; char c = (char)x; byte b = (byte)x; short s = (short)x; diff --git a/operators/Bool.java b/operators/Bool.java index 5566082a..2c48fb2e 100644 --- a/operators/Bool.java +++ b/operators/Bool.java @@ -19,9 +19,9 @@ public class Bool { System.out.println("i == j is " + (i == j)); System.out.println("i != j is " + (i != j)); // Treating an int as a boolean is not legal Java: -//! System.out.println("i && j is " + (i && j)); -//! System.out.println("i || j is " + (i || j)); -//! System.out.println("!i is " + !i); + //- System.out.println("i && j is " + (i && j)); + //- System.out.println("i || j is " + (i || j)); + //- System.out.println("!i is " + !i); System.out.println("(i < 10) && (j < 10) is " + ((i < 10) && (j < 10)) ); System.out.println("(i < 10) || (j < 10) is " diff --git a/polymorphism/RTTI.java b/polymorphism/RTTI.java index 4f561195..0ce65e1b 100644 --- a/polymorphism/RTTI.java +++ b/polymorphism/RTTI.java @@ -29,7 +29,7 @@ public class RTTI { x[0].f(); x[1].g(); // Compile time: method not found in Useful: - //! x[1].u(); + //- x[1].u(); ((MoreUseful)x[1]).u(); // Downcast/RTTI ((MoreUseful)x[0]).u(); // Exception thrown } diff --git a/references/CheckCloneable.java b/references/CheckCloneable.java index 5773dd80..c5697cbf 100644 --- a/references/CheckCloneable.java +++ b/references/CheckCloneable.java @@ -90,7 +90,7 @@ public class CheckCloneable { Ordinary x = new Ordinary(); // This won't compile; // clone() is protected in Object: - //! x = (Ordinary)x.clone(); + //- x = (Ordinary)x.clone(); // Checks first to see if a class // implements Cloneable: for(Ordinary ord1 : ord) { diff --git a/references/HorrorFlick.java b/references/HorrorFlick.java index 7e03a477..671616ad 100644 --- a/references/HorrorFlick.java +++ b/references/HorrorFlick.java @@ -29,8 +29,8 @@ public class HorrorFlick { Hero h = new Hero(); Scientist s = new Scientist(); MadScientist m = new MadScientist(); - //! p = (Person)p.clone(); // Compile error - //! h = (Hero)h.clone(); // Compile error + //- p = (Person)p.clone(); // Compile error + //- h = (Hero)h.clone(); // Compile error s = (Scientist)s.clone(); m = (MadScientist)m.clone(); } diff --git a/reuse/FinalArguments.java b/reuse/FinalArguments.java index 44577694..6721f59f 100644 --- a/reuse/FinalArguments.java +++ b/reuse/FinalArguments.java @@ -10,7 +10,7 @@ class Gizmo { public class FinalArguments { void with(final Gizmo g) { - //! g = new Gizmo(); // Illegal -- g is final + //- g = new Gizmo(); // Illegal -- g is final } void without(Gizmo g) { g = new Gizmo(); // OK -- g not final diff --git a/reuse/FinalData.java b/reuse/FinalData.java index 55bf606e..2cbf0f77 100644 --- a/reuse/FinalData.java +++ b/reuse/FinalData.java @@ -33,14 +33,14 @@ public class FinalData { } public static void main(String[] args) { FinalData fd1 = new FinalData("fd1"); - //! fd1.valueOne++; // Error: can't change value + //- fd1.valueOne++; // Error: can't change value fd1.v2.i++; // Object isn't constant! fd1.v1 = new Value(9); // OK -- not final for(int i = 0; i < fd1.a.length; i++) fd1.a[i]++; // Object isn't constant! - //! fd1.v2 = new Value(0); // Error: Can't - //! fd1.VAL_3 = new Value(1); // change reference - //! fd1.a = new int[3]; + //- fd1.v2 = new Value(0); // Error: Can't + //- fd1.VAL_3 = new Value(1); // change reference + //- fd1.a = new int[3]; System.out.println(fd1); System.out.println("Creating new FinalData"); FinalData fd2 = new FinalData("fd2"); diff --git a/reuse/FinalOverridingIllusion.java b/reuse/FinalOverridingIllusion.java index f562abab..dbd91996 100644 --- a/reuse/FinalOverridingIllusion.java +++ b/reuse/FinalOverridingIllusion.java @@ -42,12 +42,12 @@ public class FinalOverridingIllusion { // You can upcast: OverridingPrivate op = op2; // But you can't call the methods: - //! op.f(); - //! op.g(); + //- op.f(); + //- op.g(); // Same here: WithFinals wf = op2; - //! wf.f(); - //! wf.g(); + //- wf.f(); + //- wf.g(); } } /* Output: diff --git a/reuse/Jurassic.java b/reuse/Jurassic.java index 724fd9c5..3a576149 100644 --- a/reuse/Jurassic.java +++ b/reuse/Jurassic.java @@ -13,7 +13,7 @@ final class Dinosaur { void f() {} } -//! class Further extends Dinosaur {} +//- class Further extends Dinosaur {} // error: Cannot extend final class 'Dinosaur' public class Jurassic { diff --git a/serialization/Blips.java b/serialization/Blips.java index 6c079f19..4862c088 100644 --- a/serialization/Blips.java +++ b/serialization/Blips.java @@ -56,8 +56,8 @@ public class Blips { b1 = (Blip1)in.readObject(); } // OOPS! Throws an exception: -//! System.out.println("Recovering b2:"); -//! b2 = (Blip2)in.readObject(); + //- System.out.println("Recovering b2:"); + //- b2 = (Blip2)in.readObject(); } } /* Output: