Code violates the Eclipse compiler

During a lingering game with lambda expressions, I created the following code:

 Supplier<Map<String, Function<UserNetworkEntry, Boolean>>> _groupBuilder = () -> {Arrays.stream(UserType.values())
            .collect(Collectors.toMap(
                    value -> value.toString(),
                    value -> (UserNetworkEntry entry) -> entry.userType == value)))
            .putAll(_usersModel._users.stream()
                    .map(user -> user.organization)
                    .distinct()
                    .collect(Collectors.toMap(
                            organization -> organization, 
                            organization -> entry -> entry.organization.equals(organization))));};
        System.notAPartOfTheSystem.println("Hm");
        int word = "String";

As you probably see the last two lines, this really does not need to be compiled. The problem is that this happens: according to Eclipse (Neon), the above code type checks, compiles and even runs. (The runtime behavior is also odd, the method executes to the line _groupBuilder=, but then the method calmly returns without executing any additional code ... an error does not occur. What else, I found that I can copy and paste this code anywhere and get the same behavior.

(By the way, it’s better not to worry about what the code is trying to do. I know this is terrible, it's just what I played with.)

, Eclipse/Java Compiler, , . , Eclipse - , "" - ​​ , , .

- , ?

+4

Source: https://habr.com/ru/post/1651115/


All Articles