O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 run do not change:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required