Practice ยท 2 of 3
Beat Primitive Obsession
Introduce a value object in Solution:
- static class Email with constructor (String raw) that validates:
exactly one '@', non-empty local part and domain, domain contains a
'.' after the '@'. Invalid โ IllegalArgumentException.
Store a normalized (trimmed, lowercased) final field value with
getter value().
- static List<String> uniqueEmails(List<String> rawList) โ parses each
into Email (invalid ones skipped) and returns distinct normalized
values, insertion order.
Strings stay strings at the edges; inside this code, an Email is not a
String.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Clean Code Lab