-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8, 17
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Their is one custom class Employee{
String code,
String countryCode
//getters
//setters
//constructor's
//equals and hascode
}
Now we have two sets of type Employee say set1 and set2 and the values are as follows.
set1.add(new Employee("B1HY1001", "IN"));
set1.add(new Employee("B1HY1002", "US"));
set2.add(new Employee("B1HY1001", "US"));
set2.add(new Employee("B1HY1002", "US"));
Set<Employee> s = set2().filter(e -> e.getCode().equals("B1HY1001")).collect(Collectors.toSet());
s.forEach(s1->s1.setCountryCode("IN"));
set2.removeAll(set1);
// set2 Not able to remove 1 element i.e. Employee("B1HY1001", "US") but if I do reverse i.e. set1.removeAll(set2) then in set1 it will remove
Also I observed that hashcode is same in both the sets for element Employee("B1HY1001", "US") even equals method giving true for this element in both the sets.
If hashcode is same and they are equals then ideally is should be removed.
FREQUENCY : always
Their is one custom class Employee{
String code,
String countryCode
//getters
//setters
//constructor's
//equals and hascode
}
Now we have two sets of type Employee say set1 and set2 and the values are as follows.
set1.add(new Employee("B1HY1001", "IN"));
set1.add(new Employee("B1HY1002", "US"));
set2.add(new Employee("B1HY1001", "US"));
set2.add(new Employee("B1HY1002", "US"));
Set<Employee> s = set2().filter(e -> e.getCode().equals("B1HY1001")).collect(Collectors.toSet());
s.forEach(s1->s1.setCountryCode("IN"));
set2.removeAll(set1);
// set2 Not able to remove 1 element i.e. Employee("B1HY1001", "US") but if I do reverse i.e. set1.removeAll(set2) then in set1 it will remove
Also I observed that hashcode is same in both the sets for element Employee("B1HY1001", "US") even equals method giving true for this element in both the sets.
If hashcode is same and they are equals then ideally is should be removed.
FREQUENCY : always
- duplicates
-
JDK-8303939 about use "list.stream().distinct().map()" bug
-
- Closed
-