Java Reference
In-Depth Information
B.4.2. Math
The Math class includes new methods that throw an arithmetic exception if the result of the
operation overflows. These methods consist of addExact, subtractExact, multiply-Exact,
incrementExact, decrementExact, and negateExact with int and long arguments. In addition,
there's a static toIntExact method to convert a long value to an int. Other additions include the
static methods floorMod, floorDiv, and nextDown.
B.5. Files
Noticeable additions to the Files class let you produce a stream from files. We mentioned the
new static method Files.lines in chapter 5 ; it lets you read a file lazily as a stream. Other useful
static methods that return a stream include the following:
Files.list —Produces a Stream<Path> consisting of entries in a given directory. The listing isn't
recursive. Because the stream is consumed lazily, it's a useful method for processing potentially very
large directories.
Files.walk —Just like Files.list , it produces a Stream<Path> consisting of entries in a given
directory. But the listing is recursive and the depth level can be configured. Note that the traversal is
performed depth-first.
Files.find —Produces a Stream<Path> from recursively traversing a directory to find entries that
match a given predicate.
B.6. Reflection
We discussed several changes to the annotation mechanism in Java 8 in appendix A . The
Reflection API was updated to support these changes.
Another addition to the Reflection API is that information about parameters of methods such as
names and modifiers can now be accessed with the help of the new java.lang.reflect.Parameter
class, which is referenced in the new java.lang .reflect.Executable class that serves as a shared
superclass for the common functionality of Method and Constructor.
B.7. String
The String class now includes a convenient static method called join to—as you may guess—join
strings with a delimiter! You can use it as follows:
 
Search WWH ::




Custom Search