Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33388
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2015-12-24 13:11 -0800 |
| References | <downcast-20151224203323@ram.dialup.fu-berlin.de> <n5hje9$lpa$1@dont-email.me> |
| Message-ID | <16c26297-e33f-424c-a5dd-c6980d0b64f1@googlegroups.com> (permalink) |
| Subject | Re: Today I invented ... the downcast! |
| From | Lew <lewbloch@gmail.com> |
On Thursday, December 24, 2015 at 12:12:32 PM UTC-8, Eric Sosman wrote:
> On 12/24/2015 2:39 PM, Stefan Ram wrote:
> > What do you all thing about it?
>
> Meh.
>
> > Example of the intended usage:
> >
> > final android.widget.LinearLayout.LayoutParams parameters
> > = downcast( params );
> >
> > Definition:
> >
> > static private final< T, O >T downcast( O x ){ return( T )x; }
> >
> > Main Advantage (that's why I wrote it):
> >
> > - the programmer conveys his intention that this
> > cast is intended to be a /down/cast
>
> Since an /up/cast requires no cast operator at all, the mere
> presence of the cast is a pretty good indicator. Besides,
>
> String s = "I feel sad and downcast. (:";
> Object o = downcast(s); // "down?"
>
> > Advantages that are mere side-effects of the implementation:
> >
> > - the programmer does not actually have to write
> > the target type, which is deduced
> >
> > Disadvantage:
> >
> > - It has not yet been extensively tested
> >
> > - It does not check at compile time whether T
> > really is a /sub/type of O.
>
> ... thus converting a compile-time error into a run-time error,
> a wrong in the step direction. Hmm: I withdraw my "Meh" above, and
> change it instead to "Ugh."
<O, T extends O>
But the unchecked cast
(T) O
is problematic, and exactly the sort of thing generics are supposed to obviate.
Define the logic for which you think you need casting to use a <T extends U> in the first place.
--
Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Today I invented ... the downcast! Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-24 15:12 -0500 Re: Today I invented ... the downcast! Lew <lewbloch@gmail.com> - 2015-12-24 13:11 -0800
csiph-web