Suppressing Java Findbugs error (EI_EXPOSE_REP)

前端 未结 2 784
忘掉有多难
忘掉有多难 2021-01-18 07:44

I have a Java gettor method that looks like the following:

import java.util.Date;
//...
public Date getSomeDate() {
  return someDate;
}

an

2条回答
  •  我在风中等你
    2021-01-18 08:30

    No,we need to clone that object using below code :

    public Date getSomeDate() {
      return new Date(someDate.getTime()).clone();
    }
    

提交回复
热议问题