since MyMenuBar is-a MenuBar there is an implicit typecast, so you can
do
MenuBar myBar = new MyMenuBar(..)
you can of course downcast the MenuBar to MyMenuBar, if you're sure it
is a MyMenuBar
@alexoffspring
i'm wondering how you initialize the *root* with your MyMenuBar, if
doing this way:
MenuBar root = new MenuItem("MyMenuBar", new MyMenuBar(false));
MyMenuBar myMenuBar = (MyMenubar)root.getSubMenu();
then the cast shall be working like a charm....
On 20 Okt., 03:31, Prashant <[email protected]> wrote:
> you can typecast *MyMenuBar *to *MenuBar *but not the other way round. Here
> you are trying to typecast *MenuBar* to *MyMenuBar*.
>
> On 19 October 2010 21:28, alexoffspring <[email protected]> wrote:
>
>
>
> > Thanks guys.
>
> > Ok, i got the error in the constructor. Now it sounds like this:
>
> > > public class MyMenuBar extends MenuBar {
>
> > // super constructor
> > public MyMenuBar(boolean bool) {
> > super(bool);
> > } ;
>
> > But still i got the same ClassCastException.
>
> > root is a MenuItem and root.getSubMenu() return a MenuBar
> > object.
>
> > On 19 Ott, 17:39, ep <[email protected]> wrote:
> > > where do you make new MyMenuBar() and how do you provide it to the
> > > "root" member? and what type is root actually?
>
> > > On 19 Okt., 17:14, alexoffspring <[email protected]> wrote:
>
> > > > I created a public class MyMenuBar just to use the getItems()
> > > > method, which is protected in MenuBar:
> > > > ........
> > > > public class MyMenuBar extends MenuBar {
>
> > > > // super constructor
> > > > public MyMenuBar(boolean bool) {
> > > > new MenuBar(bool);
> > > > }
>
> > > > // the super.getItems() is protected
> > > > public List<MenuItem> getItems() {
> > > > return super.getItems();
> > > > }
>
> > > > };
>
> > > > ........
>
> > > > I don't understand why a get a java.lang.ClassCastException when i
> > > > try to cast a MenuBar into a MyMenuBar:
>
> > > > .........
> > > > MenuBar menuBar = root.getSubMenu();
> > > > local_mmb = ((MyMenuBar) menuBar).getItems();
> > > > ........
>
> > > > Where am i wrong?- Nascondi testo citato
>
> > > - Mostra testo citato -
>
> > --
> > 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]<google-web-toolkit%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> --
> Prashantwww.claymus.com
> code.google.com/p/claymus/
--
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.