September 2018
Intermediate to advanced
802 pages
19h 30m
English
With the getWeightKg(int pounds) method accepting the input parameter, the method name can be misleading because it does not capture the weight unit of the input parameter. We could try and name it getWeightKgFromPounds(int pounds) but it does not make the method function clearer. After realizing it, we decided to make the convertPoundsToKg(int pounds) method public and to remove the getWeightKg(int pounds) method at all. Since the convertPoundsToKg(int pounds) method does not require access to the object fields, it can be static, too:
public interface Truck extends Vehicle { int getPayloadPounds(); default int getPayloadKg(int pounds){ return convertPoundsToKg(pounds); } static int convertKgToPounds(int kilograms){ return ...Read now
Unlock full access