MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / Parcel10

Class Parcel10

innerclasses/Parcel10.java:8–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6// construction on an anonymous inner class
7
8public class Parcel10 {
9 public Destination
10 destination(final String dest, final float price) {
11 return new Destination() {
12 private int cost;
13 // Instance initialization for each object:
14 {
15 cost = Math.round(price);
16 if(cost > 100)
17 System.out.println("Over budget!");
18 }
19 private String label = dest;
20 @Override
21 public String readLabel() { return label; }
22 };
23 }
24 public static void main(String[] args) {
25 Parcel10 p = new Parcel10();
26 Destination d = p.destination("Tasmania", 101.395F);
27 }
28}
29/* Output:
30Over budget!
31*/

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected