Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33387 > unrolled thread
| Started by | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| First post | 2015-12-24 15:12 -0500 |
| Last post | 2015-12-24 13:11 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-12-24 15:12 -0500 |
| Subject | Re: Today I invented ... the downcast! |
| Message-ID | <n5hje9$lpa$1@dont-email.me> |
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."
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2015-12-24 13:11 -0800 |
| Message-ID | <16c26297-e33f-424c-a5dd-c6980d0b64f1@googlegroups.com> |
| In reply to | #33387 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web