Anonymous-Inner classes showing incorrect modifier

Note that the wording in the JLS of that particular section has changed significantly since then. It now (JLS 11) reads: 15.9.5. Anonymous Class Declarations: An anonymous class is never final (§8.1.1.2). The fact that an anonymous class is not final is relevant in casting, in particular the narrowing reference conversion allowed for the cast … Read more

Case sensitivity of Java class names

Are there any guarantees about which classes are loadable by the bootstrap class loader in every JVM? The core bits and pieces of the language, plus supporting implementation classes. Not guaranteed to include any class that you write. (The normal JVM loads your classes in a separate classloader from the bootstrap one, and in fact … Read more

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.