java - 即使使用 Long 类型,整数也太大
问题描述
我在使用 Long 类型属性时遇到问题,我创建了一个名为“Cnh”的属性,它接收一个 11 位代码,我已经将 L 放在了值的末尾,但是当我在 JUnit 中运行它时,它仍然显示 Integer number大号:06161567318l。
有什么可能的方法可以避免它我不想更改属性类型,因为我有另一个有同样问题的但它是一个“哈希码”(这真的很难改变)
设置值
public void setUp() {
cli = new Cliente();
cli.setEmail("lucasoaresleite@gmail.com");
cli.setCpf(06161567318l);
cli.setCnh(06161567318l);
cli.setCnpj("--");
cli.setDataNascimento("23081998");
cli.setNomeCompleto("Lucas Soares");
cli.setNomeFantasia("--");
}
JUnit 测试
public void testSetCnh() {
assertEquals(06161567318l, cli.getCnh());
}
公共类 Cliente 实现 Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "cpf")
private Long cpf;
@Basic(optional = false)
@Column(name = "nome_completo")
private String nomeCompleto;
@Basic(optional = false)
@Column(name = "data_nascimento")
private String dataNascimento;
@Basic(optional = false)
@Column(name = "email")
private String email;
@Basic(optional = false)
@Column(name = "cnh")
private Long cnh;
@Column(name = "cnpj")
private String cnpj;
@Column(name = "nome_fantasia")
private String nomeFantasia;
public Cliente() {
}
public Cliente(Long cpf) {
this.cpf = cpf;
}
public Cliente(Long cpf, String nomeCompleto, String dataNascimento, String email, Long cnh) {
this.cpf = cpf;
this.nomeCompleto = nomeCompleto;
this.dataNascimento = dataNascimento;
this.email = email;
this.cnh = cnh;
}
public Long getCpf() {
return cpf;
}
public void setCpf(Long cpf) {
this.cpf = cpf;
}
public String getNomeCompleto() {
return nomeCompleto;
}
public void setNomeCompleto(String nomeCompleto) {
this.nomeCompleto = nomeCompleto;
}
public String getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(String dataNascimento) {
this.dataNascimento = dataNascimento;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Long getCnh() {
return cnh;
}
public void setCnh(Long cnh) {
this.cnh = cnh;
}
public String getCnpj() {
return cnpj;
}
public void setCnpj(String cnpj) {
this.cnpj = cnpj;
}
public String getNomeFantasia() {
return nomeFantasia;
}
public void setNomeFantasia(String nomeFantasia) {
this.nomeFantasia = nomeFantasia;
}
@Override
public int hashCode() {
int hash = 0;
hash += (cpf != null ? cpf.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Cliente)) {
return false;
}
Cliente other = (Cliente) object;
if ((this.cpf == null && other.cpf != null) || (this.cpf != null && !this.cpf.equals(other.cpf))) {
return false;
}
return true;
}
@Override
public String toString() {
return "alocar.java.models.Cliente[ cpf=" + cpf + " ]";
}
}
我需要它接受大于限制的值(我知道......但我也知道你知道我在说什么)]:)
解决方案
推荐阅读
- java - Java File.getCanonicalFile() 无法处理冒号':'
- java - 为什么 SimpleDateFormat 用错误的月份和日期解析日期?
- java - 如何删除Java中特定字符之间的子字符串?
- c# - 使用 aspnetcore 信号器作为 system.io 流阻塞
- c++ - 基于 compare_exchange 的循环是否受益于暂停?
- git - 如何确定 git stash 的来源
- jquery - 如何制作一个
- python-3.x - python-igraph:shortest_paths_dijkstra 的多个权重属性
- r - 根据 R 中前一行的值将行转换为列
- r - 在 igraph 中取消命名顶点 - R