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 to do it...

  1. Look at the Car interface again:
        public interface Truck extends Vehicle {          int getPayloadPounds();        }
  1. Instead of the getPayloadKg() method, introduce a more general method and enum for supporting the metric system of weight units:
        int getPayload(WeigthUnit weightUnit);        enum WeigthUnit { Pound, Kilogram }

Such an enhancement allows you to have more flexibility in future.

  1. Deprecate the getPayloadPounds() method and add a Javadoc with explanations:
        /**        * Returns the payload of the truck.        *        * @return the payload of the truck in the specified units        * of weight measurements        * @deprecated As of API 2.1, to avoid adding methods        * for each possible weight unit,        * use {@link #getPayload(WeigthUnit weightUnit)} instead.        */ @Deprecated(since ...

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