Skip to content

Commit 1852556

Browse files
committed
Builds and runs with JDK9
1 parent be5962b commit 1852556

18 files changed

+46
-22
lines changed

collectiontopics/CanonicalMapping.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public boolean equals(Object r) {
1919
return r instanceof Element &&
2020
Objects.equals(ident, ((Element)r).ident);
2121
}
22+
@SuppressWarnings("deprecation")
2223
@Override
2324
protected void finalize() {
2425
System.out.println("Finalizing " +

collectiontopics/References.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class VeryBig {
1313
VeryBig(String id) { ident = id; }
1414
@Override
1515
public String toString() { return ident; }
16+
@SuppressWarnings("deprecation")
1617
@Override
1718
protected void finalize() {
1819
System.out.println("Finalizing " + ident);

collectiontopics/SetOrder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class SetOrder {
2323
for(String type: sets) {
2424
System.out.format("[-> %s <-]%n",
2525
type.substring(type.lastIndexOf('.') + 1));
26-
@SuppressWarnings("unchecked")
26+
@SuppressWarnings({"unchecked", "deprecation"})
2727
Set<String> set = (Set<String>)
2828
Class.forName(type).newInstance();
2929
set.addAll(RLIST);

generics/DynamicProxyMixin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static Object newInstance(Tuple2... pairs) {
4444

4545
public class DynamicProxyMixin {
4646
public static void main(String[] args) {
47+
@SuppressWarnings("unchecked")
4748
Object mixin = MixinProxy.newInstance(
4849
tuple(new BasicImp(), Basic.class),
4950
tuple(new TimeStampedImp(), TimeStamped.class),

generics/InstantiateGenericType.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://OnJava8.com for more book information.
55
import java.util.function.*;
6+
import java.lang.reflect.InvocationTargetException;
67

78
class ClassAsFactory<T> implements Supplier<T> {
89
Class<T> kind;
910
ClassAsFactory(Class<T> kind) {
1011
this.kind = kind;
1112
}
13+
@SuppressWarnings("deprecation")
1214
@Override
1315
public T get() {
1416
try {
1517
return kind.newInstance();
16-
} catch(InstantiationException |
17-
IllegalAccessException e) {
18+
} catch(Exception e) {
1819
throw new RuntimeException(e);
1920
}
2021
}

generics/coffee/CoffeeSupplier.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.*;
88
import java.util.function.*;
99
import java.util.stream.*;
10+
import java.lang.reflect.InvocationTargetException;
1011

1112
public class CoffeeSupplier
1213
implements Supplier<Coffee>, Iterable<Coffee> {
@@ -21,10 +22,13 @@ public CoffeeSupplier() {}
2122
public Coffee get() {
2223
try {
2324
return (Coffee)
24-
types[rand.nextInt(types.length)].newInstance();
25+
types[rand.nextInt(types.length)]
26+
.getConstructor().newInstance();
2527
// Report programmer errors at run time:
26-
} catch(InstantiationException |
27-
IllegalAccessException e) {
28+
} catch(InstantiationException |
29+
NoSuchMethodException |
30+
InvocationTargetException |
31+
IllegalAccessException e) {
2832
throw new RuntimeException(e);
2933
}
3034
}

housekeeping/TerminationCondition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Book {
1414
void checkIn() {
1515
checkedOut = false;
1616
}
17+
@SuppressWarnings("deprecation")
1718
@Override
1819
public void finalize() {
1920
if(checkedOut)

onjava/BasicSupplier.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Supplier from a class with a no-arg constructor
66
package onjava;
77
import java.util.function.*;
8+
import java.lang.reflect.InvocationTargetException;
89

910
public class BasicSupplier<T> implements Supplier<T> {
1011
private Class<T> type;
@@ -15,8 +16,10 @@ public BasicSupplier(Class<T> type) {
1516
public T get() {
1617
try {
1718
// Assumes type is a public class:
18-
return type.newInstance();
19+
return type.getConstructor().newInstance();
1920
} catch(InstantiationException |
21+
NoSuchMethodException |
22+
InvocationTargetException |
2023
IllegalAccessException e) {
2124
throw new RuntimeException(e);
2225
}

onjava/atunit/AtUnit.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ Method checkForCleanupMethod(Method m) {
162162
}
163163
} else { // Use the no-arg constructor:
164164
try {
165-
return testClass.newInstance();
165+
return testClass
166+
.getConstructor().newInstance();
166167
} catch(InstantiationException |
168+
NoSuchMethodException |
169+
InvocationTargetException |
167170
IllegalAccessException e) {
168171
throw new RuntimeException(
169172
"Couldn't create a test object. " +

patterns/BoxObserver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import onjava.MouseClick;
1414

1515
// You must inherit a new type of Observable:
16+
@SuppressWarnings("deprecation")
1617
class BoxObservable extends Observable {
1718
@Override
1819
public void notifyObservers(Object b) {
@@ -22,6 +23,7 @@ public void notifyObservers(Object b) {
2223
}
2324
}
2425

26+
@SuppressWarnings("deprecation")
2527
public class BoxObserver extends JFrame {
2628
Observable notifier = new BoxObservable();
2729
public BoxObserver(int grid) {
@@ -45,6 +47,7 @@ public static void main(String[] args) {
4547
}
4648
}
4749

50+
@SuppressWarnings("deprecation")
4851
class OCBox extends JPanel implements Observer {
4952
Observable notifier;
5053
int x, y; // Locations in grid

0 commit comments

Comments
 (0)