Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34087
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Daniel Pitts <usenet@coloraura.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: IsSupertypeOf |
| Date | Thu, 7 Apr 2016 22:19:40 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 53 |
| Message-ID | <ne7er8$ar1$1@dont-email.me> (permalink) |
| References | <IsSubtypeOf-20160407185025@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Fri, 8 Apr 2016 05:16:25 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="024e2fa8da3cc1e109236b5469830e67"; logging-data="11105"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19A2mmY6eFRtyCoY1u2lgVcW4ynBJnvWWo=" |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <IsSubtypeOf-20160407185025@ram.dialup.fu-berlin.de> |
| Cancel-Lock | sha1:ulSYEGVODBK/DeoofQpb8WDw+aU= |
| Xref | csiph.com comp.lang.java.programmer:34087 |
Show key headers only | View raw
On 4/7/16 11:05 AM, Stefan Ram wrote:
> I usually explain supertypes with the Java SE API documentation.
>
> But maybe it could also help to show programs to illustrate
> this notion.
>
> For example,
>
> void f( java.lang.String s ){ java.lang.CharSequence c = s; }
>
> compiles because »java.lang.CharSequence« is a supertype of
> »java.lang.String«. So, can one say that
>
> void f( S s ){ T t = s; }
>
> compiling is equivalent to T being a supertype of S? (Assuming
> that autoboxing and autounboxing were disabled.)
I think you're conflating "assignability" with "subtypes".
if that compiles, Objects of types S are assignable to containers of type T.
void f( int s ) { double t = s; }
This isn't saying that 'double' is a subclass of 'int'. Indeed, it
would fail Liskov Substitution Principle pretty badly.
>
> There can be no instances of »java.lang.Math«, but the following
> code still compiles:
>
> void f( java.lang.Math m ){ java.lang.Object o = m; }
>
> (it can even be executed: »f( null )«.)
>
> . BTW: One can't use
>
> ( java.lang.String )null instanceof java.lang.CharSequence
>
> , that is,
>
> ( S )null instanceof T
>
> , since this indeed prints »false« because there is no
> real object behind the left operand.
>
> So, I might have found a »compile-time« IsSupertypeOf,
> which might fail due to autoboxing, but not run-time
> IsSupertypeOf. Maybe someone sees some more errors or
> possibilities for improvements?
>
I recall reading about type theory in which "null" is the "universal
subtype" and "Object" would represent the "universal super type" in Java.
Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread
Re: IsSupertypeOf Daniel Pitts <usenet@coloraura.com> - 2016-04-07 22:19 -0700
csiph-web