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


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

Re: Every expression has a type?

From Wayne <wayne@nospam.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Every expression has a type?
Date 2017-10-31 03:07 -0400
Organization A noiseless patient Spider
Message-ID <ot97eq$47m$1@dont-email.me> (permalink)
References <Every-20171030130857@ram.dialup.fu-berlin.de>

Show all headers | 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