Java 11 Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

The following code demonstrates the new addition:

public static void main(String... arg) {
int horsePower = 246;
int payload = Truck.convertKgToPounds(1500);
int vehicleWeight = Truck.convertKgToPounds(1800);
Truck truck =
FactoryVehicle.buildTruck(payload, vehicleWeight, horsePower);
System.out.println("Weight in pounds: " + vehicleWeight);
int kg = truck.getWeightKg(vehicleWeight);
System.out.println("Weight converted to kg: " + kg);
System.out.println("Weight converted back to pounds: " +
Truck.convertKgToPounds(kg));
}

The results of the test do not change: