答案 0 :(得分:2)
消息来源与您的观察结果并不矛盾:
public static final KeyGenerator getInstance(String algorithm)
throws NoSuchAlgorithmException {
if (algorithm == null) {
throw new NullPointerException("algorithm == null");
}
Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
return new KeyGenerator((KeyGeneratorSpi) sap.spi, sap.provider, algorithm);
}
可能是单身人士的是SpiAndProvider
返回的ENGINE#getInstance
。如果您进一步了解实现情况,每次调用getInstance
时都会有一个新实例并不奇怪,因为KeyGenerator
有实例成员,使用您通过调用传递的参数启动。< / p>