为什么有BigInteger(String)但没有BigInteger(long)? [英] Why is there BigInteger(String) but no BigInteger(long)?

查看:134
本文介绍了为什么有BigInteger(String)但没有BigInteger(long)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,要使用构造函数new BigInteger(String)将String转换为BigInteger,而要使用工厂函数BigInteger.valueof(long)转换int/long,为什么?

In Java, to convert a String to BigInteger you use the constructor new BigInteger(String) but to convert an int/long you use the factory function BigInteger.valueof(long), why is that?

推荐答案

实际上一个BigInteger(long)构造函数,但它是私有的.工厂方法上的javadoc提供有关原因的信息:

There actually is a BigInteger(long) constructor, but it's private. The javadoc on the factory method provides info on why:

此静态工厂方法"优先于(长)提供 构造函数,因为它允许重复使用经常使用的 BigIntegers.

This "static factory method" is provided in preference to a (long) constructor because it allows for reuse of frequently used BigIntegers.

这篇关于为什么有BigInteger(String)但没有BigInteger(long)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆