CodeSOD: Functionally Null

This post was originally published on this site

The Daily WTF

Starting in Java 8, Java introduced support for lambdas. Under the hood, they’re a soup of anonymous classes, generics (and the associated type erasure), but they at least look like (and mostly behave like) lambdas. Functional programming came to Java a decade ago.

Ich‘s predecessor saw this new tool and decided that they needed to use it everywhere.

public final class Account2BankConnection implements Function<Account, BankConnection> { @Override public BankConnection apply(final Account account) { final Iban iban = new Function<String, Iban>() { @Override public Iban apply(final String input) { return input != null ? new Iban(input) : null; } }.apply(account.getIban()); final Bic bic = new Function<String, Bic>() { @Override public Bic apply(final String input) { return input != null ? new Bic(input) : null; } }.apply(account.getBic()); return new BankConnection(iban, bic, account.getOwner()); } }

The goal of this code is to take a bank account and construct the correct bank connection

To read the full article click on the 'post' link at the top.