Sorry, I fat fingered that last post.

Once again, by inner class I mean something like ...

public MyOuterClass
{
  MyInner class = new MyInnerClass();

  public MyInnerClass
  {
  }
}

I think this was avail in 1.4 - unless I am confusing things.

By defining a class inline I mean ...

greetingService.greetServer(textToServer,
                                                new AsyncCallback<String>() {
                                                        public void 
onFailure(Throwable caught) {
                                                                // Show the RPC 
error message to the user
                                                                dialogBox
                                                                                
.setText("Remote Procedure Call - Failure");
                                                                
serverResponseLabel
                                                                                
.addStyleName("serverResponseLabelError");
                                                                
serverResponseLabel.setHTML(SERVER_ERROR);
                                                                
dialogBox.center();
                                                                
closeButton.setFocus(true);
                                                        }

                                                        public void 
onSuccess(String result) {
                                                                
dialogBox.setText("Remote Procedure Call");
                                                                
serverResponseLabel
                                                                                
.removeStyleName("serverResponseLabelError");
                                                                
serverResponseLabel.setHTML(result);
                                                                
dialogBox.center();
                                                                
closeButton.setFocus(true);
                                                        }
                                                });

... and this comes right from the Eclipse starter project for GWT.

My initial reaction was that this was a little hard to read.  I am
getting a little used to it, but I think I still prefer to implement
the callback in a 'real' class (an inner class somewhere else in the
file works for me).

I guess it just comes down to code style.

Thanks, Jan.

On Aug 23, 8:49 am, jack <[email protected]> wrote:
> Good question - lol.
>
> I think maybe we're not quite using the same terminology - maybe we
> are.
>
> By inner class I mean something like ...
>
> public MyOuterClass
> {
>
> }
>
> On Aug 23, 1:34 am, Jan Ehrhardt <[email protected]> wrote:
>
> > It's common practice to use inner classes in Java for listeners or other
> > simple things like callbacks.
> > What you want to do in the case of a callback, is invoking a method after
> > the the asynchronous RPC has been finished. The easiest solution would be,
> > to put this method as an argument to the RPC method, but since Java has no
> > closures, using inner classes is a nice solution. In Java 1.4, where no
> > inner classes where available, people implemented the AsyncCallback
> > interface in the class, which was calling the RPC method, so they could do
> > something like:
>
> > service.getSomthing(this);
>
> > But with Java 5 inner classes have become the prefered way.
> > Sure, you can also create your own class for this, but that's the worse
> > practice, I think.
>
> > What would be the best solution for this, you think?
>
> > Regards
> > Jan Ehrhardt
>
> > On Sat, Aug 22, 2009 at 10:43 PM, jack <[email protected]> wrote:
>
> > > In every RPC example I've seen, AsyncCallback are all defined inline?
> > > Why is this so?  What are the advantages?
>
> > > Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to