Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30534

Re: Jbutton and JLabel

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Jbutton and JLabel
Date 2014-12-09 13:56 -0500
Organization A noiseless patient Spider
Message-ID <m67gjh$8u6$1@dont-email.me> (permalink)
References <cec907d9-e353-47a2-9684-5255e437dd1b@googlegroups.com> <m67cv8$nrh$1@dont-email.me> <87ba2a82-4117-4756-96e4-e7d71976eea7@googlegroups.com>

Show all headers | View raw


On 12/9/2014 1:31 PM, colmjkav@gmail.com wrote:
> lol. Thanks. I guess I found the compiler message a bit confusing as if it hadnt heard of JLabel.

     (Context: Compiler rejected `JLabel qLabel = JLabel("Question:");')

     In truth, the compiler hadn't heard of `JLabel' -- as a method
name.  In the context

	... = IDENTIFIER ( EXPRESSION ) ;

the IDENTIFIER must be a method name; nothing else would parse.  So the
compiler looked for a method named `JLabel', failed to find one, and
told you so.

     The correction I suggested (insert the `new' keyword) is almost
certainly what you intended.  However, another possible correction
would have been to write a new method elsewhere in the class:

	private JLabel JLabel(String title) {
	    return new JLabel(title);
	}

This may at first look erroneous (and it certainly wouldn't survive
a code review!), but it's really the same as

	private JLabel labelMaker(String title) {
	    return new JLabel(title);
	}

... except for the change of name.  The compiler can tell from the
context which `JLabel' occurrences are type names and which are
method names.

     A fundamental problem with generating diagnostic messages for an
erroneous source is that the source is, well, erroneous.  There are
many correct codes at different "edit distances" from an incorrect
original, and the compiler can't read your mind to tell which of the
many possibilities you might have intended.  "The" error is essentially
the difference between the flawed original and a guessed-at "nearby"
alternative, and the alternative the compiler plucks out of the cloud
may not be close to what you wanted.  It is, after all, guessing --
because the original incorrect program didn't say what you meant.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Jbutton and JLabel colmjkav@gmail.com - 2014-12-09 09:52 -0800
  Re: Jbutton and JLabel Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-12-09 12:53 -0500
    Re: Jbutton and JLabel colmjkav@gmail.com - 2014-12-09 10:31 -0800
      Re: Jbutton and JLabel Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-12-09 13:56 -0500

csiph-web