Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37630
| Path | csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Every expression has a type? |
| Date | Tue, 31 Oct 2017 13:06:35 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 46 |
| Message-ID | <otaair$79q$1@dont-email.me> (permalink) |
| References | <Every-20171030130857@ram.dialup.fu-berlin.de> <ot97eq$47m$1@dont-email.me> <void-20171031161320@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Tue, 31 Oct 2017 17:06:35 -0000 (UTC) |
| Injection-Info | reader02.eternal-september.org; posting-host="1b614658fe07273569ba5a813d538965"; logging-data="7482"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tujEZSxHPWx12IF41AGor" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 |
| In-Reply-To | <void-20171031161320@ram.dialup.fu-berlin.de> |
| Content-Language | en-US |
| Cancel-Lock | sha1:RBdFc7RbZwDxad5ebbk73dudW9o= |
| Xref | csiph.com comp.lang.java.programmer:37630 |
Show key headers only | View raw
On 10/31/2017 11:13 AM, Stefan Ram wrote:
> [...]
> We can have types of expressions, which do not have any
> value at all. For example consider this program:
>
> public final class Main
> {
>
> public static double test( final int i ){ return i; }
>
> public static void main( final java.lang.String[] args ) {} }
>
> The compiler will check that the type »int« of the return
> expression »i« is a subtype of the type of the return type
> »double«. So, »i« has a type. But »i« does never have a value
> in this program.
The compiler doesn't require that the type of `i' be a subtype
of the return type. If it did, the example would not compile: `int'
is not a subtype of `double'. The compiler requires, rather, that
the expression in the `return' produce a value that is convertible
to the method's returned type, and that's a far weaker requirement.
> So, »i« is an expression, it has a type, but not a value.
I think all you're saying is that code not executed doesn't
execute. That is, what you say of `i' is also true of `args':
If the main() method is not called, `args' has no value.
> So, it actually would be perfectly fine for the call of
> a void-method to have a type but not a value, as is the
> case in many other languages like, for example, C, where
> »void« is a type.
`void' is a type in C, but not a type in Java. `if' can test an
`int' expression in C, but not in Java. `->' is an operator in C, but
not in Java. `goto' is a statement in C, but a reserved and meaningless
word in Java. So what? Different languages assign different meanings
to similar symbols. `Gift' in English is something that you'd like to
receive, but that in German you'd probably refuse.[*]
[*] https://translate.google.com/#de/en/Gift
--
esosman@comcast-dot-net.invalid
Eleven hundred seventy-seven days to go.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Every expression has a type? Wayne <wayne@nospam.invalid> - 2017-10-31 03:07 -0400 Re: Every expression has a type? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-10-31 12:00 -0400 Re: Every expression has a type? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-10-31 13:06 -0400
csiph-web