标签:返回值 forms shape byte evo disabled tps cti transform
Lambda Expressions, a new language feature, has been introduced in this release. They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.
传统的匿名对象方式:
List<String> names = Arrays.asList("peter", "anna", "mike", "xenia"); Collections.sort(names, new Comparator<String>() { @Override public int compare(String a, String b) { return b.compareTo(a); } });
java 8:
Collections.sort(names, (String a, String b) -> { return b.compareTo(a); });
对于函数体只有一行代码的,可以去掉大括号{}以及return关键字:
Collections.sort(names, (String a, String b) -> b.compareTo(a));
Java编译器可以自动推导出参数类型:
Collections.sort(names, (a, b) -> b.compareTo(a));
Method references provide easy-to-read lambda expressions for methods that already have a name.
Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces.
允许我们给接口添加一个非抽象的方法实现,只需要使用 default关键字即可,这个特征又叫做扩展方法。
interface Formula { double calculate(int a); default double sqrt(int a) { return Math.sqrt(a); } }
Repeating Annotations provide the ability to apply the same annotation type more than once to the same declaration or type use.
支持多重注解
@Repeatable(Hints.class) @interface Hint { String value(); } @Hint("hint1") @Hint("hint2") class Person {}
Type Annotations provide the ability to apply an annotation anywhere a type is used, not just on a declaration. Used with a pluggable type system, this feature enables improved type checking of your code.
Improved type inference.
Method parameter reflection.
Classes in the new java.util.stream
package provide a Stream API to support functional-style operations on streams of elements. The Stream API is integrated into the Collections API, which enables bulk operations on collections, such as sequential or parallel map-reduce transformations.
public interface Collection<E> extends Iterable<E> { default Stream<E> stream() { return StreamSupport.stream(spliterator(), false); } } public interface Stream<T> extends BaseStream<T, Stream<T>> { Stream<T> filter(Predicate<? super T> predicate); <R> Stream<R> map(Function<? super T, ? extends R> mapper); IntStream mapToInt(ToIntFunction<? super T> mapper); LongStream mapToLong(ToLongFunction<? super T> mapper); DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper); <R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper); IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper); LongStream flatMapToLong(Function<? super T, ? extends LongStream> mapper); DoubleStream flatMapToDouble(Function<? super T, ? extends DoubleStream> mapper); Stream<T> distinct(); Stream<T> sorted(); Stream<T> sorted(Comparator<? super T> comparator); Stream<T> peek(Consumer<? super T> action); Stream<T> limit(long maxSize); Stream<T> skip(long n); void forEach(Consumer<? super T> action); void forEachOrdered(Consumer<? super T> action); Object[] toArray(); <A> A[] toArray(IntFunction<A[]> generator); T reduce(T identity, BinaryOperator<T> accumulator); // Optional避免空指针异常? Optional<T> reduce(BinaryOperator<T> accumulator); <U> U reduce(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner); <R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner); <R, A> R collect(Collector<? super T, A, R> collector); Optional<T> min(Comparator<? super T> comparator); Optional<T> max(Comparator<? super T> comparator); long count(); boolean anyMatch(Predicate<? super T> predicate); boolean allMatch(Predicate<? super T> predicate); boolean noneMatch(Predicate<? super T> predicate); Optional<T> findFirst(); Optional<T> findAny(); // Static factories // ...省略构造流的方法和内部类 }
Performance Improvement for HashMaps with Key Collisions
AccessController.doPrivileged
that enables code to assert a subset of its privileges, without preventing the full traversal of the stack to check for other permissionsjava.security.DomainLoadStoreParameter
, and the new command option -importpassword
for the keytool utilityjava.security.cert.PKIXRevocationChecker
class for configuring revocation checking of X.509 certificatesSwingNode
class enables developers to embed Swing content into JavaFX applications. See the SwingNode
javadoc and Embedding Swing Content in JavaFX Applications.DatePicker
and the TreeTableView
controls.javafx.print
package provides the public classes for the JavaFX Printing API. See the javadoc for more information.Shape3D
(Box
, Cylinder
, MeshView
, and Sphere
subclasses), SubScene
, Material
, PickResult
, LightBase
(AmbientLight
and PointLight
subclasses) , and SceneAntialiasing
API classes have been added to the JavaFX 3D Graphics library. The Camera
API class has also been updated in this release. See the corresponding class javadoc for javafx.scene.shape.Shape3D
, javafx.scene.SubScene
, javafx.scene.paint.Material
, javafx.scene.input.PickResult
, javafx.scene.SceneAntialiasing
, and the Getting Started with JavaFX 3D Graphics document.WebView
class provides new features and improvements. Review Supported Features of HTML5 for more information about additional HTML5 features including Web Sockets, Web Workers, and Web Fonts.javafx.css
javadoc for more information.ScheduledService
class allows to automatically restart the service.jjs
command is provided to invoke the Nashorn engine.java
command launches JavaFX applications.java
man page has been reworked.jdeps
command-line tool is provided for analyzing class files.jarsigner
tool has an option for requesting a signed time stamp from a Time Stamping Authority (TSA).-parameters
option of the javac
command can be used to store formal parameter names and enable the Reflection API to retrieve formal parameter names.javac
command.javac
tool now has support for checking the content of javadoc
comments for issues that could lead to various problems, such as invalid HTML or accessibility issues, in the files that are generated when javadoc
is run. The feature is enabled by the new -Xdoclint
option. For more details, see the output from running "javac -X
". This feature is also available in the javadoc
tool, and is enabled there by default.javac
tool now provides the ability to generate native headers, as needed. This removes the need to run the javah
tool as a separate step in the build pipeline. The feature is enabled in javac
by using the new -h
option, which is used to specify a directory in which the header files should be written. Header files will be generated for any class which has either native methods, or constant fields annotated with a new annotation of type java.lang.annotation.Native
.javadoc
tool supports the new DocTree
API that enables you to traverse Javadoc comments as abstract syntax trees.javadoc
tool supports the new Javadoc Access API that enables you to invoke the Javadoc tool directly from a Java application, without executing a new process. See the javadoc what‘s new page for more information.javadoc
tool now has support for checking the content of javadoc
comments for issues that could lead to various problems, such as invalid HTML or accessibility issues, in the files that are generated when javadoc
is run. The feature is enabled by default, and can also be controlled by the new -Xdoclint
option. For more details, see the output from running "javadoc -X
". This feature is also available in the javac
tool, although it is not enabled by default there.URLPermission
is now used to allow connections back to the server from which they were started. SocketPermission
is no longer granted.SelectorProvider
implementation for Solaris based on the Solaris event port mechanism. To use, run with the system property java.nio.channels.spi.Selector
set to the value sun.nio.ch.EventPortSelectorProvider
.<JDK_HOME>/jre/lib/charsets.jar
filejava.lang.String(byte[], *)
constructor and the java.lang.String.getBytes()
method.JDBC 4.2 introduces new features.
java.net.URLPermission
has been added.java.net.HttpURLConnection
, if a security manager is installed, calls that request to open a connection require permission.java.util.concurrent
package.java.util.concurrent.ConcurrentHashMap
class to support aggregate operations based on the newly added streams facility and lambda expressions.java.util.concurrent.atomic
package to support scalable updatable variables.java.util.concurrent.ForkJoinPool
class to support a common pool.java.util.concurrent.locks.StampedLock
class has been added to provide a capability-based lock with three modes for controlling read/write access.Hardware intrinsics were added to use Advanced Encryption Standard (AES). The UseAES
and UseAESIntrinsics
flags are available to enable the hardware-based AES intrinsics for Intel hardware. The hardware must be 2010 or newer Westmere hardware.
Note: AES intrinsics are only supported by the Server VM.
For example, to enable hardware AES, use the following flags:
-XX:+UseAES -XX:+UseAESIntrinsics
To disable hardware AES use the following flags:
-XX:-UseAES -XX:-UseAESIntrinsics
Removal of PermGen.
Default Methods in the Java Programming Language are supported by the byte code instructions for method invocation.
al.forEach(x->{
AcceptMethod.printValur(x);
});
al.forEach(AcceptMethod::printValur);
// 方法参数
Consumer<String> methodParam = AcceptMethod::printValur;
// 方法执行accept
al.forEach(x -> methodParam.accept(x));
这种[方法引用]或者说[双冒号运算]对应的参数类型是Function<T,R>
T表示传入类型,R表示返回类型。比如表达式person -> person.getAge();
传入参数是person,返回值是person.getAge(),那么方法引用Person::getAge
就对应着Function<Person,Integer>
类型。
java.lang:
public interface Iterable<T> {
...
default void forEach(Consumer<? super T> action) {
Objects.requireNonNull(action);
for (T t : this) {
action.accept(t);
}
}
}
java.util.function:
// 注解@FunctionalInterface保证了接口有且仅有一个抽象方法
@FunctionalInterface
public interface Consumer<T> {
void accept(T t);
...
}
https://www.jianshu.com/p/0bf8fe0f153b
https://blog.csdn.net/lsmsrc/article/details/41747159
标签:返回值 forms shape byte evo disabled tps cti transform
原文地址:https://www.cnblogs.com/angelica-duhurica/p/12166139.html