[haXe] conditionnal if else

filt3r at free.fr filt3r at free.fr
Tue Apr 10 18:50:26 CEST 2007


hmmm, ok thanks for the quick answer ;)
I won't cast it to Button, I'll do the 2nd case, it's also fast.
But, as I said, writing "var b : Button..." I thought that it will be
automatically casted, especially when both extends Button (= the same type) :(
That's ok, I just wanted to know, it's a bit confusing me.
Thanks for your answer,
Michel

Selon Franco Ponticelli <franco.ponticelli at gmail.com>:

> When you use if to return values all the blocks must return the same type.
> This doesn't apply in conditions that are without assignment.
> In your first sample try  to cast both to Button.
>
> On 4/10/07, filt3r at free.fr <filt3r at free.fr> wrote:
> >
> > Re :)
> > I've another mistake for today :D, when I write :
> >
> > var b : Button = if ( _bMultiSelect ) new CheckButton () else new
> > RadioButton
> > ();
> >
> > compiler gives me : "RadioButton should be CheckButton"
> > And when I write :
> >
> > var b : FButton;
> > if ( _bMultiSelect )
> >         b = new CheckButton ()
> > else
> >         b = new FRadioButton ();
> >
> > All works correctly.
> > If in the 1st case I wouldn't write "var b : Button = ..." but "var b =
> > ...", I
> > wouldn't be surprised because of inference, but here I don't understand.
> > Is it an mistake or I'm wrong ? (I know it's not really important but I
> > would
> > know)
> > N:B: CheckButton and RadioButton extends both "Button"
> > Thanks,
> > Michel
> >
> > --
> > haXe - an open source web programming language
> > http://haxe.org
> >
>





More information about the Haxe mailing list