[haXe] conditionnal if else
Franco Ponticelli
franco.ponticelli at gmail.com
Tue Apr 10 18:57:42 CEST 2007
The problem is not the cast to the Button type but the difference between
CheckButton and RadioButton types. If both the condition results in a
CheckButton or a RadioButton the cast was not necessary. I understand you
perplexity about the automatic casting but this is a standard behavior in
many strictly typed languages, c# does exactly the same.
On 4/10/07, filt3r at free.fr <filt3r at free.fr> wrote:
>
> 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
> > >
> >
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.motion-twin.com/pipermail/haxe/attachments/20070410/250f669a/attachment.htm
More information about the Haxe
mailing list