Lambda expression and method overloading doubts

I think you found this bug in the compiler: JDK-8029718 (or this similar one in Eclipse: 434642). Compare to JLS §15.12.2.1. Identify Potentially Applicable Methods: … A lambda expression (§15.27) is potentially compatible with a functional interface type (§9.8) if all of the following are true: The arity of the target type’s function type is … Read more

Is “public static final” redundant for a constant in a Java interface?

Variables declared in Interface are implicitly public static final. This is what JLS 9.3 says : Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields. Read through the JLS to get an idea why … Read more

How to create a class literal of a known type: Class

You can always cast to what you need, like this return (Class<List<String>>) new ArrayList<String>().getClass(); or return (Class<List<String>>) Collections.<String>emptyList().getClass(); But I assume that’s not what you are after. Well it works, with a warning, but it isn’t exactly “beautiful”. I just found this Why is there no class literal for wildcard parameterized types? Because a wildcard … Read more

Why can’t we access static content via uninitialized local variable?

§15.11. Field Access Expressions: If the field is static: The Primary expression is evaluated, and the result is discarded. If evaluation of the Primary expression completes abruptly, the field access expression completes abruptly for the same reason. Where earlier it states that field access is identified by Primary.Identifier. This shows that even though it seems … Read more

Order of execution of parameters guarantees in Java?

From the Java Language Specification (on Expressions): 15.7.4 Argument Lists are Evaluated Left-to-Right In a method or constructor invocation or class instance creation expression, argument expressions may appear within the parentheses, separated by commas. Each argument expression appears to be fully evaluated before any part of any argument expression to its right.

Why no static methods in Interfaces, but static fields and inner classes OK? [pre-Java8] [duplicate]

An official proposal has been made to allow static methods in interfaces in Java 7. This proposal is being made under Project Coin. My personal opinion is that it’s a great idea. There is no technical difficulty in implementation, and it’s a very logical, reasonable thing to do. There are several proposals in Project Coin … Read more

Effectively final vs final – Different behavior

First of all, we are talking about local variables only. Effectively final does not apply to fields. This is important, since the semantics for final fields are very distinct and are subject to heavy compiler optimizations and memory model promises, see $17.5.1 on the semantics of final fields. On a surface level final and effectively … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)