Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37616

Re: Every expression has a type?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Wayne <wayne@nospam.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Every expression has a type?
Date Tue, 31 Oct 2017 03:07:02 -0400
Organization A noiseless patient Spider
Lines 48
Message-ID <ot97eq$47m$1@dont-email.me> (permalink)
References <Every-20171030130857@ram.dialup.fu-berlin.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Injection-Date Tue, 31 Oct 2017 07:07:06 -0000 (UTC)
Injection-Info reader02.eternal-september.org; posting-host="3b62dabfd3287b4e48f519aaa53e8910"; logging-data="4342"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UNrL3Mrmb2a875YIsJl8ZlD4SOWBwDe0="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0
In-Reply-To <Every-20171030130857@ram.dialup.fu-berlin.de>
Content-Language en-US
Cancel-Lock sha1:FJjOjX0H3mSDZDlgsmadoEZ3FYA=
Xref csiph.com comp.lang.java.programmer:37616

Show key headers only | View raw


On 10/30/2017 8:29 AM, Stefan Ram wrote:
>   I was flabbergasted. I had made some handwritten notes
>   during my course, and one read:
> 
> _Jeder_ Ausdruck hat einen Typ.
> 
>   indicating that I wrote "Jeder Ausdruck hat einen Typ."
>   ("Every expression has a type.") in my published HTML
>   course notes, and that there was something wrong with
>   "Jeder" ("Every").
> 
>   But I can't remember what I was thinking of when I wrote
>   this. How can there be an expression in Java without a type?
>   So, eventually, I discarded my note.
> 
>   Still, I was wondering ...
> 
>   Then it struck my mind!
> 
>   The JLS says:
> 
>       THE Java programming language is a statically typed
>       language, which means that every variable and every
>       expression has a type that is known at compile time.
> 
>   But what's the type of a call of a method with the result
>   (jls9:8.4.5) »void«?
> 
>   In Java, »void« is not a type!
> 
>   So, »java.lang.System.out.println()« is an expression,
>   but does it have a type?
> 

See 15.1, where all that is spelled out (Java 9 version):
<https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.1>

"An expression denotes nothing if and only if it is a method invocation (§15.12) that
invokes a method that does not return a value, that is, a method declared void
(§8.4). Such an expression can be used only as an expression statement (§14.8) or as
the single expression of a lambda body (§15.27.2), because every other context in
which an expression can appear requires the expression to denote something. ..."

So, an expression consisting of a void method invocation has no result and thus
no type.

-- 
Wayne

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


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