Java 8 Consumer/Function Lambda Ambiguity

This line is definitely ambiguous: doStuff(getPattern(x -> String.valueOf(x))); Reread this from the linked JLS chapter: 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 the same as the arity of the lambda expression. If the … Read more

Return value of assignment operator in concurrent code

I think the answer depends on the compiler. The language specifies: At run-time, the result of the assignment expression is the value of the variable after the assignment has occurred. I suppose that theoretically the value could be changed before the second (leftmost) assignment occurs. However, with Sun’s javac compiler, method1 will will turn into: … Read more

Is `1/0` a constant expression in Java? [duplicate]

The compiler is doing constant folding (precomputing trivial literal expressions). This is a case where the expression “completes abruptly”, to use the JLS verbiage, disqualifying it from meeting the definition of “constant expression”. So it’s not a bug, it’s consistent with the JLS. And yes, the expression doesn’t evaluate to a value either (warning the … Read more

Is it true that every inner class requires an enclosing instance?

The distinctions laid out in the question make perfect sense from the specification’s standpoint: an inner class has restrictions applied to it, which have nothing to do with the question of enclosing instances (it may not have static members, for example); the concept of a static nested class is basically just about namespacing; these classes … Read more

why Integer.MAX_VALUE + 1 == Integer.MIN_VALUE?

Because the integer overflows. When it overflows, the next value is Integer.MIN_VALUE. Relevant JLS If an integer addition overflows, then the result is the low-order bits of the mathematical sum as represented in some sufficiently large two’s-complement format. If overflow occurs, then the sign of the result is not the same as the sign of … Read more

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

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