different styles when coding #2

with every new release of the java jdk, new syntax sugar, paradigms and many other features are being supplied. java 7 introduced diamond operators, java 8 supported lambdas, java 9 provides modularization, java 10 contains the local variable type inference (var) and so forth. do you stick to new features or do you persist using the older notations?


style 1:

public void doSomethingStyle1() {
    final var numbersAsString = List.of("1", "3", "3", "7");
    final var map = Map.of(1, "L", 3, "E", 7, "T");
    final var fancyLogicProcessor = new FancyLogicProcessor<Integer>();
    final var parsedNumbers =         fancyLogicProcessor.parce(numbersAsString);

    parsedNumbers.stream()
            .map(number -> map.getOrDefault(number, "-"))
            .forEach(System.out::println);
}

style 2:

public void doSomethingStyle2() {
    final List<String> numbersAsString = List.of("1", "3", "3", "7");
    final Map<Integer, String> map = Map.of(1, "L", 3, "E", 7, "T");
    final FancyLogicProcessor<Integer> fancyLogicProcessor = new FancyLogicProcessor<>();
    final List<Integer> parsedNumbers = fancyLogicProcessor.parce(numbersAsString);

    for (final Integer number : parsedNumbers) {
        String orDefault = map.getOrDefault(number, "-");
        System.out.println(orDefault);
    }
}

so which style are you, 1, 2 or even something else, tell me about it in the comments. 😄



55 views0 comments

Recent Posts

See All