Joe Soltzberg

55%
Flag icon
For an unexported method, you, as the package author, control the circumstances under which the method is called, so you can and should ensure that only valid parameter values are ever passed in. Therefore, nonpublic methods can check their parameters using assertions, as shown below: Click here to view code image // Private helper function for a recursive sort private static void sort(long a[], int offset, int length) {     assert a != null;     assert offset >= 0 && offset <= a.length;     assert length >= 0 && length <= a.length - offset;     ... // Do the computation }
Joe Soltzberg
What is the point of this feature? Wouldn't it make sense to just implement yourself in a utils class that can be abstracted further if/when needed?
Effective Java
Rate this book
Clear rating
Open Preview