在Java领域中使用BigInteger?
Realm Java不支持在Java领域中使用BigInteger?,java,android,realm,biginteger,Java,Android,Realm,Biginteger,Realm Java不支持BigInteger,因此以下类: public class Bonus extends RealmObject { String thebonus; BigInteger bonus; ... public BigInteger getBonus() { return bonus; } public void setBonus(BigInteger newBonus) { this.bonus = newBon
BigInteger
,因此以下类:
public class Bonus extends RealmObject {
String thebonus;
BigInteger bonus;
...
public BigInteger getBonus() {
return bonus;
}
public void setBonus(BigInteger newBonus) {
this.bonus = newBonus;
}
}
不支持类型为“java.math.biginger”的字段“value”中的结果。
我使用的领域如下:
bnsInitial.setBonus(新的BigInteger(“0”)
或类似于intx=bns.getBonus().compareTo(新的BigInteger(“0”))的东西代码>例如
有没有一种方法可以使用Realm获得biginger
?这些值有可能定期超过Long
限制,这就是我使用biginger
的原因。
谢谢我的建议是:
- 使用
String
或byte[]
作为大整数的领域表示,并在这些类型和biginger
之间进行动态转换
- 如果要在
RealmObject
中缓存biginger
对象,请使用@Ignore
注释告知领域基础结构不要尝试传递它
大概是这样的:
public class Bonus extends RealmObject {
byte[] thebonus;
@Ignore
BigInteger bonus;
public BigInteger getBonus() {
if (bonus == null) {
bonus = new BigInteger(thebonus);
}
return bonus;
}
public void setBonus(BigInteger newBonus) {
bonus = newBonus;
thebonus = BigInteger.toByteArray();
}
}
使用byte[]
比使用String
效率更高,因为转换速度更快。。。对于足够大的整数。(以10为基数和以2为基数^N之间的文本二进制转换将需要较长的乘法和除法。)
免责声明:这只是基于阅读。我从未使用过Realm。我的建议是:
- 使用
String
或byte[]
作为大整数的领域表示,并在这些类型和biginger
之间进行动态转换
- 如果要在
RealmObject
中缓存biginger
对象,请使用@Ignore
注释告知领域基础结构不要尝试传递它
大概是这样的:
public class Bonus extends RealmObject {
byte[] thebonus;
@Ignore
BigInteger bonus;
public BigInteger getBonus() {
if (bonus == null) {
bonus = new BigInteger(thebonus);
}
return bonus;
}
public void setBonus(BigInteger newBonus) {
bonus = newBonus;
thebonus = BigInteger.toByteArray();
}
}
使用byte[]
比使用String
效率更高,因为转换速度更快。。。对于足够大的整数。(以10为基数和以2为基数^N之间的文本二进制转换将需要较长的乘法和除法。)
免责声明:这只是基于阅读。我从未使用过Realm。这仅仅是将biginger
转换为String
,然后将其传递给setBonus()
方法(在重构方法和类以使用String
而不是biginger
之后),将其保存到Realm中,然后使用getBonus()
将字符串
转换为大整数
并返回它?还是我遗漏了什么?谢谢。。。关键的@Ignore
注释。。。如果将biginger
缓存在Bonus
对象中。这仅仅是将biginger
转换为String
的问题,例如将其传递给setBonus()
方法(在重构方法和类以使用String
而不是biginger
之后),将其保存到域,然后让getBonus()
将String
转换为biginger
并返回它?还是我遗漏了什么?谢谢。。。关键的@Ignore
注释。。。如果在Bonus
对象中缓存biginger
。