Pou*_*uya 2 java types integer
我需要一个与Integer完全相同的数据类型,我希望它能溢出并下溢到某些值.换句话说,我想设置Integer类的对象/实例的MAX_VALUE和MIN_VALUE.问题是MAX_VALUE和MIN_VALUE是常量,最后是Integer类.我该怎么办?
你必须创建自己的包装类:
public class CustomInteger
{
public static final int MAX_VALUE = 5000;
public static final int MIN_VALUE = -5000;
private final int value;
public CustomInteger(int value)
{
// TODO: Validation
this.value = value;
}
// Add all the methods you want - e.g. integer operations etc
// performing custom overflow/underflow on each operation
}
Run Code Online (Sandbox Code Playgroud)
您需要决定是否需要为整个类型设置一对固定限制,或者每个实例是否可以具有不同的限制(以及将两个值添加到不同限制时的含义等).
| 归档时间: |
|
| 查看次数: |
2728 次 |
| 最近记录: |