Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 91 fix this Which code fragment will create a list of incremented integers A ls stream map Converter new inc collect Collectors toList B Converter c new Converter ls stream map c inc collect Collectors toList C ls stream map Converter inc collect Collectors toList D ls stream map i Converter inc i collect Collectors toList Answers Answer 1 The correct answer is option B This question investigates Javas static import feature This feature which was introduced in Java 15 allows static elements from one class to be used by their unqualified or short names in another source file For example given an import of the following form import static java lang Math PI a source file can simply refer to PI instead of potentially repetitively referring to Math PI This feature can be particularly useful when the static elements that are being imported have a meaning that is very well understood in the scope of the program such that the meaning doesnt benefit from the scoping efect of using a class prefix Clearly referring to Math PI is
You must have JavaScript enabled to view digital editions.