我有一个价值100023
,我已经接受了NSString
.
现在我想在包含长参数类型的Web服务中传递此值,以便如何将字符串值转换为long.
我正在检查JDK 16中IndexOutOfBoundsException的实现,我注意到long
引入了一个带有索引的新构造函数:
/**
* Constructs a new {@code IndexOutOfBoundsException} class with an
* argument indicating the illegal index.
*
* <p>The index is included in this exception's detail message. The
* exact presentation format of the detail message is unspecified.
*
* @param index the illegal index.
* @since 16
*/
public IndexOutOfBoundsException(long index) {
super("Index out of range: " + index);
}
Run Code Online (Sandbox Code Playgroud)
据我所知,数组索引通常是int
值,这在语言规范部分 §10.4 中得到证实:
数组必须按
int
值索引;short
、byte …
我正在整合由两个不同的人编写的代码,并注意到将一个String值转换为Long已经以两种不同的方式完成了.
编码器#1做到了这一点:
String strId = "12345678";
...
Long lId = new Long(strId);
Run Code Online (Sandbox Code Playgroud)
编码器#2做到了这一点:
String strId = "12345678";
...
Long lId = Long.valueOf(strId);
Run Code Online (Sandbox Code Playgroud)
从功能上讲,代码的运行方式完全相同.每个位周围都有一个try/catch块来处理NumberFormatException
抛出的任何内容.传入的字符串值是一个8位数字符串,表示一个小数:"12345678"
在两种情况下都正确地转换为Long
.
在构造函数中传递字符串和使用Long.valueOf()之间是否存在任何功能差异?我在这里检查了构造函数doc:
以及valueOf()的文档:
Long.valueOf(java.lang.String中)
据我所知,他们都调用parseLong()所以使用哪个并不重要.我只是想确保自己不会在未来的某些奇怪行为中做好准备.另外,哪种风格比其他风格更"正确"(哈哈)?
我知道一些软件商店已经通过使用int类型作为持久类的主键来烧毁.话虽如此,并非所有表格都超过20亿.事实上,大多数人没有.
那么,你们是否只将long类型用于映射到潜在大表的类或者每个持久类只是为了保持一致?什么是行业共识?
我会暂时搁置这个问题,以便您与我们分享您的成功/恐怖故事.
我正在尝试将一个大字符串(24,000到50,000个字符)传递给自托管的TCP WCF服务.
我已经将maxStringContentLength(无处不在)提升到了22008192.
我在某处读到我需要将bindingConfiguration更改为"LargeBuffer"或"LongFields",但是当我这样做时:
<endpoint address="" binding="netTcpBinding" bindingConfiguration="LongFields"
contract="ExStreamWCF.IService1">
Run Code Online (Sandbox Code Playgroud)
或这个:
<endpoint address="" binding="netTcpBinding" bindingConfiguration="LargeBuffer"
contract="ExStreamWCF.IService1">
Run Code Online (Sandbox Code Playgroud)
我的服务无法启动.我真的需要这个错误才能消失.有任何想法吗?
谢谢,
贾森
PS - 服务器上tcp服务的配置文件:
<system.serviceModel>
<services>
<service behaviorConfiguration="ExStreamWCF.Service1Behavior"
name="ExStreamWCF.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="ExStreamWCF.IService1">
<identity>
<dns value="Devexstream-2.anchorgeneral.local" />
<!--<dns value="vmwin2k3sta-tn2" />-->
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://Devexstream-2:8080/Service" />
<!--<add baseAddress="net.tcp://vmwin2k3sta-tn2:8080/Service" />-->
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ExStreamWCF.Service1Behavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
编辑:根据要求绑定
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个大小类型的字节数组long
.例如,将其视为:
long x = _________;
byte[] b = new byte[x];
Run Code Online (Sandbox Code Playgroud)
显然,您只能指定int
一个字节数组的大小.
在有人问为什么我需要一个如此大的字节数组之前,我会说我需要封装我没有编写的消息格式的数据,其中一种消息类型的长度为unsigned int(long
在Java中).
有没有办法创建这个字节数组?
我在想如果没有办法解决它,我可以创建一个字节数组输出流并继续输入它的字节,但我不知道是否对字节数组的大小有任何限制......
您的实体的ID应该是长(原始类型)还是长(对象类型)?
选择什么?长还是长?
@Entity
@Table(name = "COUNTRY")
public class CountryEntity implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID")
private long id;
@Column(name = "NAME")
private String name;
@Column(name = "CURRENCY")
private String currency;
@Column(name = "PEOPLE")
private Long people;
@Column(name = "SIZE")
private Long size;
public CountryEntity() {
}
Run Code Online (Sandbox Code Playgroud) 我一直在调查java.lang.Long
类源代码.
考虑一下:
public final class Long extends Number implements Comparable<Long> {
....
private final long value;
....
public long longValue() {
return (long)value;
}
....
}
Run Code Online (Sandbox Code Playgroud)
什么是投理由long
来long
?
为什么不在这种情况下将序列化(?)重新归类为Number类?
PS1 源代码链接
我有这些可能的解释:
PS2
我的java版本 - 1.7.0_45-b18
PS3 仅供参考:
Integer
:
public final class Integer extends Number implements Comparable<Integer> {
....
private final int value;
....
public int intValue() {
return value;
}
....
}
Run Code Online (Sandbox Code Playgroud)
Short
:
public final class Short …
Run Code Online (Sandbox Code Playgroud) 长长和长长有什么区别?他们都不能使用12位数字(600851475143),我忘记了什么吗?
#include <iostream>
using namespace std;
int main(){
long long a = 600851475143;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个代码来确定自1970年初以来的毫秒数何时将超过long的容量.以下代码似乎可以完成这项工作:
public class Y2K {
public static void main(String[] args) {
int year = 1970;
long cumSeconds = 0;
while (cumSeconds < Long.MAX_VALUE) {
// 31557600000 is the number of milliseconds in a year
cumSeconds += 3.15576E+10;
year++;
}
System.out.println(year);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码在几秒钟内执行并打印292272992.如果不是使用科学记数法,我将cumSeconds写为31558000000L
,程序似乎"永远"运行(我只是在10分钟左右后暂停).另请注意,以科学计数形式写入cumSeconds不需要指定数字最后为long
L或l.
long-integer ×10
java ×6
arrays ×2
int ×2
byte ×1
c++ ×1
coding-style ×1
entity ×1
hibernate ×1
java-16 ×1
jpa ×1
nsstring ×1
numbers ×1
objective-c ×1
persistence ×1
primary-key ×1
quota ×1
string ×1
types ×1
wcf ×1