-2

Method accepts only anonymous arrays, like:

setSomeValue(new String[] {'v1', 'v2', 'v3'));

I want to copy the values of another array into this anonymous array before sending it to the setSomeValue method.

The setsomeValue method:

public void setSomeValue(String[] pArrayName) { vararray = pArrayName; } 

public void getSomeValue() { return vararray;} 

But the place where getSomeValue is called does some Rql Querys and etc.

QueryExpression valueQE =
    pQueryBuilder.createConstantQueryExpression(getSomeValue());

I think this is key this method createConstantQueryExpression expects and Object! but all along I'm setting String[] array, but since its anonymous, its being treated as an Object.

ANSWER: Sorry guys for confusing you.. yes you all are geniuses dont underestimate yourselves lol.. The problem was that the query which was being generated was not right, there were issues with the content, the array itself was processed properly whether it was an anonymous array or not! and YES there is no condition where a method will accept only an anonymous array (atleast not in this case)

Leena Samuel
  • 67
  • 2
  • 12
  • 5
    Wait, what? It's impossible for a method to accept _only_ anonymous arrays. – Louis Wasserman Apr 25 '12 at 16:48
  • how is that done? Show us that method, or name it if you didn't write it. – 11684 Apr 25 '12 at 16:51
  • with this exact code, the scenario you describe is impossible, but perhaps google assigning arrays or something, perhaps it is strange behaviour of the arrays itself and is it impossible to assign them so directly, although I have never seen something like this. – 11684 Apr 25 '12 at 17:46

2 Answers2

3

If you want to pass a copy of an array into a method, try this:

setSomeValue(Arrays.copyOf(arr, arr.length));
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • It has to do with memory name / space I think. It does not want a array name (var) to be passed.. only the values or something. Tried copying / cloning / etc. – Leena Samuel Apr 25 '12 at 16:59
  • please show us the method so we can see what arguments it expects. – dogbane Apr 25 '12 at 17:01
  • public void setSomeValue(String[] pArrayName) { vararray = pArrayName; } – Leena Samuel Apr 25 '12 at 17:32
  • @Leena if you wrote the method yourself, show us the whole method, if you didn't, tell us how the method is called and in which class it is. – 11684 Apr 25 '12 at 17:39
  • I've showed you the code the definition of the method and the purpose it is ultimately used for. Please see updated explanation up – Leena Samuel Apr 25 '12 at 18:26
0

The simplest way to copy an array is to use clone()

String[] array = "v1,v2,v3".split(",");
String[] someOtherArray = array.clone();
setSomeValue(someOtherArray);

BTW: This does a shallow copy.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130