本文介绍了Java自动增量id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Java进行一些编码,但它不起作用:
I am doing some coding in Java, but it doesn't work:
public class job
{
private static int count = 0;
private int jobID;
private String name;
private boolean isFilled;
public Job(, String title, ){
name = title;
isFilled = false;
jobID = ++count;
}
}
我需要在新的时候自动增加Id条目已创建。
I need to auto-increment the Id when a new entry is created.
推荐答案
试试这个:
Try this:
public class Job {
private static final AtomicInteger count = new AtomicInteger(0);
private final int jobID;
private final String name;
private boolean isFilled;
public Job(String title){
name = title;
isFilled = false;
jobID = count.incrementAndGet();
}
这篇关于Java自动增量id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!