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


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

Re: Type of an expression

Started byArne Vajhøj <arne@vajhoej.dk>
First post2017-01-25 19:15 -0500
Last post2017-01-25 19:15 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#36219 — Re: Type of an expression

FromArne Vajhøj <arne@vajhoej.dk>
Date2017-01-25 19:15 -0500
SubjectRe: Type of an expression
Message-ID<o6bf25$1shh$1@gioia.aioe.org>
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


[toc] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web