1 2 Previous Next 17 Replies Latest reply: Dec 6, 2009 11:57 PM by 3004 RSS

    Constructors and Static context

    843789
      This time, let's all restrict everything to the terms in JLS.

      The defination of "static context" is In JLS 8.1.3 Inner Classes and Enclosing Instances.
      I quotes:
      "A statement or expression occurs in a static context if and only if the innermost
      method, *constructor*, instance initializer, static initializer, field initializer, or
      explicit constructor invocation statement enclosing the statement or expression is
      a static method, a static initializer, the variable initializer of a static variable, or an
      explicit constructor invocation statement (8.8.7)."

      In my last bloody thread, some guru had argued that [constructors do not embrace a static context|http://forums.sun.com/thread.jspa?threadID=5418750&start=45](http://forums.sun.com/thread.jspa?threadID=5418750&start=45). Then what the purpose of the "constructor" in the above difination?

      My question is about the relationship between constructors and static context. To be specific, is there any chance for constructors be a static context? If the answer is a "yes", then please give me some example; or if the answer is a "no", tell please tell me what the lexical appearance of "constructor" in the JLS defination of "static context" for?
        • 1. Re: Constructors and Static context
          DrClap
          The purpose of the word "constructor" is to refer to the general concept of the constructor in Java. Read and interpret the entire sentence to divine its meaning. If you think the mere presence of the word "constructor" and the phrase "static context" in the same sentence is sufficient to establish that a constructor "is" a static context, then you are even stupider than you appeared to be in that other thread.
          • 2. Re: Constructors and Static context
            843789
            DrClap wrote:
            If you think the mere presence of the word "constructor" and the phrase "static context" in the same sentence is sufficient to establish that a constructor "is" a static context, then you are even stupider than you appeared to be in that other thread.
            1. John has a belly.
            2. John is a dancer

            Hence,from 1 and 2 ,John is a belly dancer.
            • 3. Re: Constructors and Static context
              3004
              This was completely answered in your other thread. In that thread, I explained why your interpretation of the quoted JLS passage is wrong. I also gave an example of what is a static context as referred to in that passage. You can post as many threads as you want, but that does not change the fact that the body of a constructor is most definitely not a static context. Constructors are not static.

              Edited by: jverd on Dec 6, 2009 9:46 PM
              • 4. Re: Constructors and Static context
                843789
                punter wrote:
                DrClap wrote:
                If you think the mere presence of the word "constructor" and the phrase "static context" in the same sentence is sufficient to establish that a constructor "is" a static context, then you are even stupider than you appeared to be in that other thread.
                1. John has a belly.
                2. John is a dancer

                Hence,from 1 and 2 ,John is a belly dancer.
                Stop being childish, I have tolerant your illiterate a long thread. Please read my post carefully, do not just pick up words in my post and make your own sentence.
                • 5. Re: Constructors and Static context
                  DrClap
                  Actually... I don't think the rodent is quite that stupid. I just think he believes the word "constructor" can be removed from that definition without altering its meaning. (Perhaps he also believes that the statement implies that a constructor can be a static context, but it's pretty clear that the end of the sentence defines what can actually be a static context.)

                  Consider this static initializer:
                  static {
                    System.out.println("whatever"); // A
                    class Inner {
                      public Inner() {
                        System.out.println("huh"); // B
                      }
                    }
                  }
                  Now for the statement commented "// A", the innermost method, constructor, instance initializer, static initializer, field initializer, or explicit constructor invocation statement enclosing the statement is a static initializer, and hence it's in a static context.

                  Whereas for the statement commented "// B", the innermost method, constructor, instance initializer, static initializer, field initializer, or explicit constructor invocation statement enclosing the statement is a constructor, and hence it is not in a static context.

                  If you removed the word "constructor" from the definition, that would mean that // B is in a static context, since now the innermost method, instance initializer, static initializer, field initializer, or explicit constructor invocation statement enclosing the statement would be the static initializer. That is incorrect, and therefore the word "constructor" cannot be removed.

                  If you think about it, it's pretty clear that the phrase "method, constructor, instance initializer, static initializer, field initializer, or explicit constructor invocation statement" is simply intended to enumerate all the possible ways to make an identifiable block of code in Java. It isn't intended to imply that any or all of them could possibly be static contexts, that's just reading the definition with a large helping of assumptions.
                  • 6. Re: Constructors and Static context
                    843789
                    w.rodent wrote:
                    punter wrote:
                    DrClap wrote:
                    If you think the mere presence of the word "constructor" and the phrase "static context" in the same sentence is sufficient to establish that a constructor "is" a static context, then you are even stupider than you appeared to be in that other thread.
                    1. John has a belly.
                    2. John is a dancer

                    Hence,from 1 and 2 ,John is a belly dancer.
                    Stop being childish,
                    This was explained to you in that "bloody" thread of yours.
                    I have tolerant your illiterate a long thread.
                    Same here.
                    Please read my post carefully, do not just pick up words in my post and make your own sentence.
                    I have read all of your posts very carefully and hence I am giving this reply.Don't you see it actually boosts your statement ?
                    • 7. Re: Constructors and Static context
                      843789
                      jverd wrote:
                      This was completely answered in your other thread. In that thread, I explained why your interpretation of the quoted JLS passage is wrong. You can post as many threads as you want, but that interpretation will continue to be wrong. The body of a constructor is most definitely not a static context. Constructors are not static.
                      Could we please forget my last question, it is a closure. And forcus on this one. Do not let your impression on the last "static" question bias this question. Check carefully my question, I do not have intention to say "Constructors are static" at all.

                      If you think constructors have not even a slight little chance to have relationship with static context, please tell me what the "constructor" in the JLS defination of "static context" for?

                      Please, just do not ruin this thread.
                      • 8. Re: Constructors and Static context
                        DrClap
                        w.rodent wrote:
                        If you think constructors have not even a slight little chance to have relationship with static context, please tell me what the "constructor" in the JLS defination of "static context" for?
                        I just did that. Reply 5.
                        • 9. Re: Constructors and Static context
                          3004
                          w.rodent wrote:
                          jverd wrote:
                          This was completely answered in your other thread. In that thread, I explained why your interpretation of the quoted JLS passage is wrong. You can post as many threads as you want, but that interpretation will continue to be wrong. The body of a constructor is most definitely not a static context. Constructors are not static.
                          Could we please forget my last question, it is a closure.
                          No, because you're just asking the same thing, and it was completely answered there.
                          If you think constructors have not even a slight little chance to have relationship with static context, please tell me what the "constructor" in the JLS defination of "static context" for?
                          Your logic is "constructors are mentioned in the same sentence with the definition of static context. Therefore, constructors must be static." This is so ridiculous as to not warrant further comment.
                          • 10. Re: Constructors and Static context
                            3004
                            DrClap wrote:
                            w.rodent wrote:
                            If you think constructors have not even a slight little chance to have relationship with static context, please tell me what the "constructor" in the JLS defination of "static context" for?
                            I just did that. Reply 5.
                            And I did, with a slightly different take, in his other thread.
                            • 11. Re: Constructors and Static context
                              843789
                              Thanks a lot.
                              Now this time, I feel stupid~!
                              • 12. Re: Constructors and Static context
                                DrClap
                                jverd wrote:
                                DrClap wrote:
                                w.rodent wrote:
                                If you think constructors have not even a slight little chance to have relationship with static context, please tell me what the "constructor" in the JLS defination of "static context" for?
                                I just did that. Reply 5.
                                And I did, with a slightly different take, in his other thread.
                                That thread was far too long for me to catch up on. Fortunately it only took me a couple of minutes to devise and compile my SSCCCE (Short, Self Contained, Correct Counter-Example) so if my naive hope that talking logically to fanatics was too naive, I haven't wasted much time.
                                • 13. Re: Constructors and Static context
                                  3004
                                  DrClap wrote:
                                  jverd wrote:
                                  DrClap wrote:
                                  w.rodent wrote:
                                  If you think constructors have not even a slight little chance to have relationship with static context, please tell me what the "constructor" in the JLS defination of "static context" for?
                                  I just did that. Reply 5.
                                  And I did, with a slightly different take, in his other thread.
                                  That thread was far too long for me to catch up on.
                                  Apparently it was too long for the OP to read too. :-)
                                  • 14. Re: Constructors and Static context
                                    DrClap
                                    w.rodent wrote:
                                    Thanks a lot.
                                    Now this time, I feel stupid~!
                                    Well, I figured there must be some reason for it. After all the people who wrote the rules of Java are smarter than either of us (at least in the field of designing computer languages), so they wouldn't put useless things in the rules. So to produce a test case for the word "constructor" you would have to write some code where a constructor is physically located inside something which is a static context. Easiest thing for a static context is a static initializer, although a static method would do just as well. Now how to get a constructor in there? An inner class is how. The rest is just making sure it compiles.
                                    1 2 Previous Next