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


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

Re: Type of an expression

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Type of an expression
Date 2017-01-25 19:15 -0500
Organization Aioe.org NNTP Server
Message-ID <o6bf25$1shh$1@gioia.aioe.org> (permalink)
References <type-20170126001819@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 1/25/2017 6:37 PM, Stefan Ram wrote:
> public final class Main
> { public static void main( final java.lang.String[] args )
>   { main( args.length==0?"":0 ); }}
>
> Main.java:36: error: method main in class Main cannot be applied to given types;
>   { main( args.length==0?"":0 ); }}
>     ^
>   required: String[]
>   found: args.lengt[...]" : 0
>   reason: argument mismatch; bad type in conditional expression
>       String cannot be converted to String[]
> 1 error

> public final class Main
> { public static void main( final java.lang.String[] args )
>   { main( args.length==0?0:"" ); }}
>
> Main.java:36: error: method main in class Main cannot be applied to given types;
>   { main( args.length==0?0:"" ); }}
>     ^
>   required: String[]
>   found: INT#1
>   reason: argument mismatch; INT#1 cannot be converted to String[]
>   where INT#1,INT#2 are intersection types:
>     INT#1 extends Object,Serializable,Comparable<? extends INT#2>
>     INT#2 extends Object,Serializable,Comparable<?>
> 1 error

There are rules for this.

Language lawyers can find the rules in JLS 15.25.

Pragmatic programmers make sure to always have the two be the
same type to avoid confusion.

Arne


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


Thread

Re: Type of an expression Arne Vajhøj <arne@vajhoej.dk> - 2017-01-25 19:15 -0500

csiph-web