illegal start of expression in main

Hello,

I am trying to modify the array referenced by the args variable.

If I use the following code, it works fine :

public class Test {

public static void main(String[] args) {

String[] rargs = {"DOwn"};

args = rargs;

// ........

}

}

But if I use this one, compilation fails with a illegal start of expression on line 5

public class EnumTest {

public static void main(String[] args) {

args = {"DOwn"}; //line 5

//.....

}

}

I don't see what is going wrong.

Thanks for your help....

[619 byte] By [Keega] at [2007-11-27 8:39:29]
# 1

> Hello,

>

> I am trying to modify the array referenced by the

> args variable.

>

> If I use the following code, it works fine :

>

>

> public class Test {

>public static void main(String[] args) {

> String[] rargs = {"DOwn"};

>args = rargs;

> // ........

>}

> ]

>

> But if I use this one, compilation fails with a

> illegal start of expression on line 5

>

>

> public class EnumTest {

>public static void main(String[] args) {

> args = {"DOwn"}; //line 5

>//.....

>

> }

>

> I don't see what is going wrong.

>

> Thanks for your help....

The Javac compiler cannot deduce the type of the array from the element

types in the array itself; you have to help it a bit:

args= new String[] { "DOwn" };

kind regards,

Jos

JosAHa at 2007-7-12 20:37:27 > top of Java-index,Java Essentials,Java Programming...