问题是您在
Student课程中的字段是
static。您尚未显示代码,但可以这样猜测:
public class Student { private static int id; //other fields... //constructor... //getters and setters...}
只需
static从此类的字段中删除标记即可。
public class Student { //field must not be static private int id; //other non-static fields... //constructor... //getters and setters...}
请注意,删除class
static字段中的标记 不会解决问题* 。
Converter*
简而言之,
static字段属于类,而非
static字段属于类对象引用。如果
static您的
Student类中包含字段,则所有对象引用将共享该值。当具有非
static字段时,由于它们属于该类的每个实例,因此每个对象引用_将_ 具有不同的值。
更多信息:了解实例和类成员
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)