String[] args fights String... args
Hi,
I thought this error message was a joke at first, but it's for real:
Arrayz.java:15: cannot declare both in(java.lang.String,java.lang.String[]) and in(java.lang.String,java.lang.String...) in krc.utilz.Arrayz
Please, would anyone care to offer an opinion as to WHY the compiler does not differentiate betweenString[] args andString... args. ObviouslyString... args is implementedinternally asString[] args, but that really shouldn't effect the interface... and if they are internally equivalent then wny not allow a syntax that effectively declares both in one... It's just that I would have thought it was possible (and desirable) for the compiler & JVM to do the required parameter matching for both definitions... in my mind the calling parameter list of (String, String, String) is distinct from (String, String[]) ... Or does java (like C/C++) internally not differentiate between the types reference-to-String and reference-to-array-of-Strings and reference-to-array-of-array-of-Strings ?
I'm just a tad miffed about this... I mean, it's easy to work around in at least a dozen simple ways, it's just that the compiler didn't do what I expected it to do, so it should just pull it's socks up, and, well, you know, Work!
Here's the code... complete with compiler error.
package krc.utilz.stringz;
publicclass Arrayz
{
/**
* returns true if the given value is in the args list, else false.
* @param value - the value to seek
* @param args... - variable number of String arguments to look in
*/
publicstaticboolean in(String value, String... args){
for(String a : args)if(value.equals(a))returntrue;
returnfalse;
}
//Arrayz.java:15: cannot declare both in(java.lang.String,java.lang.String[]) and in(java.lang.String,java.lang.String...) in krc.utilz.Arrayz
publicstaticboolean in(String value, String[] array){
for(String s : array)if(value.equals(s))returntrue;
returnfalse;
}
}
Thanx all. Keith.

