please help understanding syntax

Discussion in 'Java' started by John Goche, Jan 7, 2012.

  1. John Goche

    John Goche Guest

    Hello,

    I am looking at the java code on the following page:

    http://gnuc.in/resources/archives/1404

    There I find the following, but I do not
    understand the syntax Auth.background() { ... }

    public void checkAccount(final Account account)
    {
    Auth.background()
    {
    @Override
    public void run()
    {
    Auth.checkAccount(account, this, new CustomCallback()
    {
    @Override
    public void handle(int resultCode)
    {
    // ...
    }
    });
    }
    });
    }

    Can someone please explain the syntax Auth.background() { ... } .
    I understand the rest of the syntax.

    Thanks,

    John Goche
    John Goche, Jan 7, 2012
    #1
    1. Advertising

  2. John Goche

    Roedy Green Guest

    On Sat, 7 Jan 2012 13:15:43 -0800 (PST), John Goche
    <> wrote, quoted or indirectly quoted
    someone who said :

    >Can someone please explain the syntax Auth.background() { ... } .
    >I understand the rest of the syntax.


    see http://mindprod.com/jgloss/anonymousclasses.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    If you can't remember the name of some method,
    consider changing it to something you can remember.
    Roedy Green, Jan 7, 2012
    #2
    1. Advertising

  3. On 07/01/12 21:15, John Goche wrote:
    > public void checkAccount(final Account account)
    > {
    > Auth.background()
    > {
    > @Override
    > public void run()
    > {
    > Auth.checkAccount(account, this, new CustomCallback()
    > {
    > @Override
    > public void handle(int resultCode)
    > {
    > // ...
    > }
    > });
    > }
    > });
    > }
    >
    > Can someone please explain the syntax Auth.background() { ... } .


    It's a syntax error, surely? Try sticking it in a syntax-aware editor
    with a 'class X { }' around it. When I add the closing brace in emacs,
    I'm told "Mismatched parentheses".

    Perhaps it's supposed to be 'new Auth.background()', though that's an
    unconventional name for a class.

    Perhaps it's supposed to be 'new Auth.background(new Runnable() { ...'.

    ....

    --
    ss at comp dot lancs dot ac dot uk
    Steven Simpson, Jan 7, 2012
    #3
  4. John Goche

    Lew Guest

    Steven Simpson wrote:
    > John Goche wrote:
    >> public void checkAccount(final Account account)
    >> {
    >> Auth.background()
    >> {
    >> @Override
    >> public void run()
    >> {
    >> Auth.checkAccount(account, this, new CustomCallback()
    >> {
    >> @Override
    >> public void handle(int resultCode)
    >> {
    >> // ...
    >> }
    >> });
    >> }
    >> });
    >> }
    >>
    >> Can someone please explain the syntax Auth.background() { ... } .

    >
    > It's a syntax error, surely? Try sticking it in a syntax-aware editor with a
    > 'class X { }' around it. When I add the closing brace in emacs, I'm told
    > "Mismatched parentheses".
    >
    > Perhaps it's supposed to be 'new Auth.background()', though that's an
    > unconventional name for a class.
    >
    > Perhaps it's supposed to be 'new Auth.background(new Runnable() { ...'.
    >
    > ...


    Whatever it's supposed to be, the code at that site is not compilable, nor
    does the author even provide complete classes. It is evidence that mere
    presence on the Web does not make for good information.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, Jan 8, 2012
    #4
  5. On 07/01/12 22:55, Steven Simpson wrote:
    > Perhaps it's supposed to be 'new Auth.background()', though that's an
    > unconventional name for a class.
    >
    > Perhaps it's supposed to be 'new Auth.background(new Runnable() { ...'.


    D'oh! For the Runnable case, I meant 'Auth.background(new Runnable()
    {...'. Too many 'new's. Not that the extra 'new' was necessarily
    wrong, just not intended.


    --
    ss at comp dot lancs dot ac dot uk
    Steven Simpson, Jan 8, 2012
    #5
  6. John Goche

    Roedy Green Guest

    On Sat, 07 Jan 2012 22:55:55 +0000, Steven Simpson <>
    wrote, quoted or indirectly quoted someone who said :

    >It's a syntax error, surely? Try sticking it in a syntax-aware editor
    >with a 'class X { }' around it. When I add the closing brace in emacs,
    >I'm told "Mismatched parentheses".


    for samples of anonymous classes that will compile, see
    http://mindprod.com/jgloss/anonymousclasses.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    One of the most useful comments you can put in a program is
    "If you change this, remember to change ?XXX? too".
    Roedy Green, Jan 16, 2012
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    545
    Big Brian
    Oct 14, 2003
  2. Fran
    Replies:
    12
    Views:
    486
  3. buddy249
    Replies:
    1
    Views:
    565
    debayan_p
    Jun 23, 2009
  4. scootiePuff
    Replies:
    0
    Views:
    165
    scootiePuff
    Apr 3, 2008
  5. MG
    Replies:
    4
    Views:
    145
Loading...

Share This Page