Yeah, I’m just saying that the benefit of using such a regex isn’t massive (unless you’re building a service which can’t send a mail).
a@b
is a syntactically correct e-mail address. Most combinations of letters, an @-symbol and more letters will be syntactically correct, which is what most typos will look like. The regex will only catch fringe cases, such as a user accidentally hitting the spacebar.
And then, personally, I don’t feel like it’s worth pulling in one of those massive regexes (+ possibly a regex library) for most use-cases.
Yep, some code examples from the official documentation. This:
printPersons( roster, (Person p) -> p.getGender() == Person.Sex.MALE && p.getAge() >= 18 && p.getAge() <= 25 );
…is syntactic sugar for this:
interface CheckPerson { boolean test(Person p); } printPersons( roster, new CheckPerson() { public boolean test(Person p) { return p.getGender() == Person.Sex.MALE && p.getAge() >= 18 && p.getAge() <= 25; } } );
…which is syntactic sugar for this:
interface CheckPerson { boolean test(Person p); } class CheckPersonEligibleForSelectiveService implements CheckPerson { public boolean test(Person p) { return p.gender == Person.Sex.MALE && p.getAge() >= 18 && p.getAge() <= 25; } } printPersons(roster, new CheckPersonEligibleForSelectiveService());
The
printPersons
function looks like this:public static void printPersons(List<Person> roster, CheckPerson tester) { for (Person p : roster) { if (tester.test(p)) { p.printPerson(); } } }
Basically, if you accept a parameter that implements an interface with only one method (
CheckPerson
), then your caller can provide you an object like that by using the lambda syntax from the first example.They had to retrofit lambdas into the language, and they sure chose the one hammer that the language has.
Source: https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html