You can easily replace myClass.isInstance(myInstance) by 
myClass.equals(myInstance.getClass())

Michel.

On Saturday, February 17, 2007 7:22:36 PM UTC+1, Ian Petersen wrote:
>
> > you're forgetting that you can use instanceof ONLY if you have a class
> > that you KNOW, at write-time. The Class.instanceOf idea (or the GWT
> > replacement for it) has no such restriction. You can e.g. make a
> > method that takes a widget and a list of class names and returns if
> > the widget is one of those. You can make this 'generic' (e.g: one
> > method that works for any list of class names and any widget). With
> > the instanceof keyword, you can't do this; you'd have to make one
> > method for each list of classes you do have.
>
> I don't want this to descend into a flamewar, so please understand I'm
> not trying to criticize anyone or anything--I just want to better
> understand what you've written.
>
> I already know that instanceof requires write-time knowledge of the
> class and that, as implemented in a full implementation of the Java
> library, java.lang.Class.isInstance() does _not_ require write-time
> knowledge of the class on which you're calling isInstance().
>
> What I'm questioning is the benefit of using isInstance() in a GWT
> client-side application.  It appears that the JRE emulation library
> for GWT does not include any instance methods for java.lang.Class,
> which makes instances of Class nearly useless within GWT except as
> tokens for use as keys in maps, or similar.
>
> You suggested using a class literal as follows:
>
> boolean b = SomeClassOrOther.class.isInstance(widget);
>
> I figured, in response, that the GWT compiler must be able to figure
> out that this is supposed to be equivalent to:
>
> boolean b = widget instanceof SomeClassOrOther;
>
> because we already know the compiler has special handling for class
> literals like Foo.class.  (This is how the compiler handles
> GWT.create(Foo.class)--it knows that Foo.class is special.)
>
> So, I'm assuming that you know that the GWT compiler can handle
> Foo.class.isInstance(bar).  It's already been established by Mike that
>
> Class foo = Foo.class;
> boolean b = foo.isInstance(bar);
>
> won't work because foo doesn't have any instance methods (besides
> those defined on Object).
>
> So, since you can't store Foo.class in a variable (or pass it as a
> parameter) and _then_ call isInstance() on it, I don't see the benefit
> of (Foo.class.isInstance(bar)) over (bar instanceof Foo) especially
> since you pointed out that, within GWT, isInstance() won't return true
> for arguments that are instances of subclasses of the method's
> subject.
>
> Ian
>
> -- 
> Tired of pop-ups, security holes, and spyware?
> Try Firefox: http://www.getfirefox.com
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/XBcYplfi4LQJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to