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


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

Re: Every expression has a type?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Every expression has a type?
Date 2017-10-31 13:06 -0400
Organization A noiseless patient Spider
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>

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


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