Мой наблюдаемый список хранит одинаковое значение для всех объектов - PullRequest
0 голосов
/ 11 марта 2020
ObservableList<Employee> employee = FXCollections.observableArrayList();

            while (resultSet.next()) {
                Employee newEmployee = new Employee(
                        resultSet.getString("eName1"),
                        resultSet.getString("eName2"),
                        resultSet.getString("eType"),
                        resultSet.getString("phoneNumber"),
                        resultSet.getInt("eSalary"),
                        resultSet.getDate("birthday").toLocalDate(),
                        resultSet.getString("password"),
                        resultSet.getBoolean("admin"));
                newEmployee.setEId(resultSet.getInt("eId"));
                newEmployee.setImageFile(new File(resultSet.getString("imageFile")));

                System.out.println(newEmployee);
                employee.add(newEmployee);
                System.out.println(employee);
        }

Результат приведенного выше кода ниже:

Frank Seo is 34 years old
[Frank Seo is 34 years old]
admin test is 27 years old
[admin Seo is 34 years old, admin test is 27 years old]
NotAdmin Test is 26 years old
[NotAdmin Seo is 34 years old, NotAdmin test is 27 years old, NotAdmin Test is 26 years old]
[NotAdmin Seo is 34 years old, NotAdmin test is 27 years old, NotAdmin Test is 26 years old]

Это конструктор Employee:

private static  int eId;
public Employee(String eName1, String eName2, String eType, String phoneNumber, int eSalary, LocalDate birthday, String password, boolean admin) throws NoSuchAlgorithmException {
        setEName1(eName1);
        setEName2(eName2);
        setEType(eType);
        setPhoneNumber(phoneNumber);
        setESalary(eSalary);
        setBirthday(birthday);
        setImageFile(new File("./src/Images/EmlpoyeeIcon.png"));
        salt = PasswordGenerator.getSalt();
        this.password = PasswordGenerator.getSHA512Password(password, salt);
        this.setAdmin(admin);
    }

Я исключил eId из construcotr, поскольку он автоматически увеличивается в база данных. Почему объекты eName1 равны друг другу?

Это данные, которые я использую. enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...