woshikid / blog

Apache License 2.0
8 stars 1 forks source link

Java17新特性 #178

Open woshikid opened 2 years ago

woshikid commented 2 years ago

始终使用严格浮点模式

无需再使用strictfp关键字,Java将始终使用严格浮点模式

伪随机数生成器

RandomGenerator random = RandomGeneratorFactory.of("Random").create();
RandomGenerator secureRandom = RandomGeneratorFactory.of("SecureRandom").create();
RandomGenerator splittableRandom = RandomGeneratorFactory.of("SplittableRandom").create();
RandomGenerator xoroshiro128PlusPlus = RandomGeneratorFactory.of("Xoroshiro128PlusPlus").create();
RandomGenerator xoshiro256PlusPlus = RandomGeneratorFactory.of("Xoshiro256PlusPlus").create();
RandomGenerator l64X256MixRandom = RandomGeneratorFactory.of("L64X256MixRandom").create();
RandomGenerator l64X128StarStarRandom = RandomGeneratorFactory.of("L64X128StarStarRandom").create();
RandomGenerator l64X128MixRandom = RandomGeneratorFactory.of("L64X128MixRandom").create();
RandomGenerator l64X1024MixRandom = RandomGeneratorFactory.of("L64X1024MixRandom").create();
RandomGenerator l32X64MixRandom = RandomGeneratorFactory.of("L32X64MixRandom").create();
RandomGenerator l128X256MixRandom = RandomGeneratorFactory.of("L128X256MixRandom").create();
RandomGenerator l128X128MixRandom = RandomGeneratorFactory.of("L128X128MixRandom").create();
RandomGenerator l128X1024MixRandom = RandomGeneratorFactory.of("L128X1024MixRandom").create();

JumpableGenerator generator = RandomGeneratorFactory.all()
        .filter(RandomGeneratorFactory::isJumpable)
        .filter(factory -> factory.stateBits() > 128)
        .findAny()
        .map(RandomGeneratorFactory::create)
        .map(JumpableGenerator.class::cast)
        .orElseThrow();

限制使用JDK内部类

删除了--illegal-access选项

Sealed类型

permits指定的类/接口必须位于同一模块或同一包中

密封类

public abstract sealed class Shape permits Circle, Rectangle, Square {}
public abstract sealed class Root {
    public static final class A extends Root {}
    public static sealed class B extends Root permits BB {}
    public static non-sealed class C extends Root {}
}

密封接口

public sealed interface Shape permits Circle, Rectangle, Square {}
public sealed interface Root {
    public final class A implements Root {}
    public sealed class B implements Root permits BB {}
    public sealed interface C extends Root permits CC {}
    public non-sealed class D implements Root {}
    public non-sealed interface E extends Root {}
}

反序列化过滤器

// -Djdk.serialFilter=java.**;com.github.test.*;!*
ObjectInputFilter filter = ObjectInputFilter.Config.createFilter("java.**;com.github.test.*;!*");
ObjectInputFilter.Config.setSerialFilter(filter);
//objectInputStream.setObjectInputFilter(filter);

// -Djdk.serialFilterFactory=com.github.test.TestFilterFactory
ObjectInputFilter.Config.setSerialFilterFactory((curr, next) -> next);