Lỗi trả về mảng rỗng trong Set Java 8

Mình có quan hệ has - a :

private Set<Role> roles; 

Dùng Stream để các roles nhưng nó lại trả về mảng rỗng như thế này ? :

static HashSet<Role> roles = new HashSet<>(
				Arrays.asList(
						new Role(1, "EMPLOYEE"), 
						new Role(2, "ADMIN"), 
						new Role(3, "MANAGER"))
				);
	static HashSet<User> users = new HashSet<>(Arrays.asList(
			new User(1, "empolyee", "[email protected]", "{noop}123",
						(roles.stream().filter(role -> role.getID() == 1))
							.collect(Collectors.toSet())
					),
			new User(2, "admin", "[email protected]", "{noop}123",
						(roles.stream().filter(role -> role.getID() == 1 && role.getID() == 2))
								.collect(Collectors.toSet())
					),
			new User(3, "manager", "[email protected]", "{noop}123",
						(roles.stream().filter(role -> role.getID() == 1 && role.getID() == 3))
								.collect(Collectors.toSet()))
				));

Cảm ơn m.n ạ :blush:

“Như thế này” là thế nào? :thinking:

Không có giá trị nào thỏa điều kiện này nhé.
Ý bạn là:

role -> role.getID() == 1 || role.getID() == 3
1 Like

Lỗi vớ vẩn quá :frowning: Cảm ơn ạ … Haizz

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?