Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37625
| Path | csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Robert Klemme <shortcutter@googlemail.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Every expression has a type? |
| Date | Tue, 31 Oct 2017 14:40:33 +0100 |
| Lines | 40 |
| Message-ID | <f5rcqjFogckU1@mid.individual.net> (permalink) |
| References | <Every-20171030130857@ram.dialup.fu-berlin.de> <m3po94xrte.fsf@sonera.fi> <null-20171030231708@ram.dialup.fu-berlin.de> <m3d1537i2r.fsf@sonera.fi> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net nNvFU5TTi9zz0ObRujcx/AVS/4Y4s6vNXcXQ3t3b/LImbT1LQ= |
| Cancel-Lock | sha1:0b0HxixgAPx3kfC19w0DfZXUKu4= |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 |
| In-Reply-To | <m3d1537i2r.fsf@sonera.fi> |
| Content-Language | en-US |
| Xref | csiph.com comp.lang.java.programmer:37625 |
Show key headers only | View raw
On 31.10.2017 11:00, Jukka Lahtinen wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> writes:
>>> How about null?
>>> Is it cosidered to have a type, since null can be any type at all?
>
>> I have written this exercise.
>> Try to predict the output of the following program.
>
>> public final class Main
>> {
>> private static void f( final java.lang.Object o )
>> { java.lang.System.out.println( "Bject" ); }
>>
>> private static void f( final java.lang.String s )
>> { java.lang.System.out.println( "Tring" ); }
>>
>> public static void main( final java.lang.String[] args )
>> { f( null ); }}
>
> Actually I'm surprised of the output of that.
> Just the opposite of what I thought.
I'd guess the compiler picks the most specific type - and since Object
is a superclass of String it will pick String. If you add a similar
method with CharSequence argument the situation does not change. But if
you add a method with argument String[] or Integer the compiler complains
The method f(Object) is ambiguous for the type Main
Now all of a sudden there are two specific types between which the
compiler cannot chose automatically.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Every expression has a type? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2017-10-30 23:13 +0200
Re: Every expression has a type? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-10-30 18:07 -0400
Re: Every expression has a type? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2017-10-31 12:00 +0200
Re: Every expression has a type? Robert Klemme <shortcutter@googlemail.com> - 2017-10-31 14:40 +0100
csiph-web