本文介绍了Java在Java中实例化Short对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道为什么我们可以这样做:
I was wondering why we can do:
Long l = 2L; Float f = 2f; Double d = 2d;甚至
Double d = new Double(2);而不是
Short s = 2s; //or whatever letter it could be也不是
Short s = new Short(2); //I know in this case 2 is an int but couldn't it be casted internally or something?为什么我们需要使用String或short来构造构造函数。
Why do we need to take the constructors either with a String or a short.
推荐答案但你可以这样做:
Short s = 2;或者这个:
Short s = new Short((short)2);或者这个:
Short s = new Short("2");只要数字在[-2 ^ 15范围内,上述任何一项都可以使用2 ^ 15-1]
Any of the above will work as long as the number is in the range [-2^15, 2^15-1]
更多推荐
Java在Java中实例化Short对象
发布评论