jls

Out-of-order writes for Double-checked locking

十年热恋 提交于 2019-12-09 05:07:55
问题 In the examples mentioned for Out-of-order writes for double-checked locking scenarios (ref: IBM article & Wikipedia Article) I could not understand the simple reason of why Thread1 would come of out synchronized block before the constructor is fully initialized. As per my understanding, creating "new" and the calling constructor should execute in-sequence and the synchronized lock should not be release till all the work in not completed. Please let me know what I am missing here. 回答1: The

Errata for Java Language Specification 3rd Edition

折月煮酒 提交于 2019-12-07 10:54:22
问题 I use JLS extensively both as a learning and teaching resource, but I've noticed that there are some errors in it. There's the simple typos (e.g. JLS 5.1.4 "convesions"), but there's also some that I consider quite serious errors. For example, JLS 18.1 The Grammar of the Java Programming Language is supposed to be the authoritative reference for the grammar of the Java language, but it contains a production rule that never gets used! (e.g. MoreStatementExpressions ). Surely this is a sign of

Import-on-demand declaration with subpackages only

喜夏-厌秋 提交于 2019-12-07 10:50:23
问题 Related : How can I compile "import pack.*" with ant/javac, when there are no such classes? Suppose we have the given package structure parent | ---a ---b where the package parent only contains the two subpackges a and b (no class is under the package parent ). The code import parent.* , situated in a package other than parent , compiled with Maven (i.e. javac ) throws a compile-time error. The error is: package parent does not exist I looked into the Java Language Specification about such a

In Java, is an expression assignable to a declared variable iff. it can be passed as a parameter declared with the same type?

て烟熏妆下的殇ゞ 提交于 2019-12-07 08:58:25
问题 This question was inspired by Java 8: Is it possible to assign a method reference to a variable?. As I currently understand (which may not be completely right), the invocation of, say fooMethod(FooType ft) as fooMethod(myFooInstance) causes an implicit assignment of myFooInstance to a local variable within fooMethod 's body, whose name is ft , and whose type is declared as FooType . Clearly, in this case, I could also assign myFooInstance to a field or local variable whose type is FooType ,

How to fully qualify a class whose package name collides with a local member name?

旧时模样 提交于 2019-12-07 08:15:30
问题 OK, here's a very curious Java 7 language puzzle for the JLS specialists out there. The following piece of code won't compile, neither with javac nor with Eclipse: package com.example; public class X { public static X com = new X(); public void x() { System.out.println(com.example.X.com); // cannot find symbol ^^^^^^^ } } It appears as though the member com completely prevents access to the com.* packages from within X . This isn't thoroughly applied, however. The following works, for

Why open a non-existing package from a Java module?

橙三吉。 提交于 2019-12-07 05:12:35
问题 The JLS 11 "7.7.2. Exported and Opened Packages" says: It is permitted for opens to specify a package which is not declared by a compilation unit associated with the current module. What would be a scenario for this? Why is this needed? 回答1: Thanks to Alan Bateman and Michael Easter for explanations, and I can think of some realistic scenarios. First, as was explained by Alan and Michael: JLS allows to "open" directories without Java types for situations when we keep resources in them. So,

Was there ever a “breaking change” in the Java language specification?

半城伤御伤魂 提交于 2019-12-06 20:53:48
问题 With the problably widely known exception of the introduction of the 'assert' keyword, has there ever been a change in the Java language specification which caused old code to be no longer compatible with newer source levels of the JDK? Summary so far (many thanks for the comments): "Older" Java code can cause compilation errors, when upgrading to a later version, if the code uses declarations using one of the keywords which where introduced in a later version of the Java language

How to fully qualify a class whose package name collides with a local member name?

半腔热情 提交于 2019-12-05 17:49:41
OK, here's a very curious Java 7 language puzzle for the JLS specialists out there. The following piece of code won't compile, neither with javac nor with Eclipse: package com.example; public class X { public static X com = new X(); public void x() { System.out.println(com.example.X.com); // cannot find symbol ^^^^^^^ } } It appears as though the member com completely prevents access to the com.* packages from within X . This isn't thoroughly applied, however. The following works, for instance: public void x() { System.out.println(com.example.X.class); } My question(s): How is this behaviour

Is the JDK documentation part of the language specification?

帅比萌擦擦* 提交于 2019-12-05 14:34:25
There is only one official Java Language Specification and all Java implementations must comply with it. How about the API documentation: do all Java implementations need to comply with this version or could an implementation define the behaviour of some methods and classes differently, as long as it's compatible with the JLS? Let's throw a concrete example: could a Java implementation include a HashMap that doesn't accept null elements? I believe, that, yes it is. Upon closer examination, I think it is not . As JLS 8 states in p.1.4 : 1.4. Relationship to Predefined Classes and Interfaces As

Errata for Java Language Specification 3rd Edition

别说谁变了你拦得住时间么 提交于 2019-12-05 13:36:55
I use JLS extensively both as a learning and teaching resource, but I've noticed that there are some errors in it. There's the simple typos (e.g. JLS 5.1.4 "convesions"), but there's also some that I consider quite serious errors. For example, JLS 18.1 The Grammar of the Java Programming Language is supposed to be the authoritative reference for the grammar of the Java language, but it contains a production rule that never gets used! (e.g. MoreStatementExpressions ). Surely this is a sign of more serious errors in other parts of the given grammar, right? So is there an errata for the 3rd