I use Generics, but not this class <T> thing!
I am trying to call this method to combine two arrays using Google Collections
public static <T> T[] concat(T[] first,
T[] second,
Class<T> type)
It returns empty results. I use
ObjectArrays.concat(array1, array2, Blah.class)
which compiles only.
array1and array2have a type Blah[].
What is the correct syntax?
Bonus question: Do other collection libraries have documentation with examples?
Edit: The problem was in my bone code.
public void register(ButtonPair[] pairs) {
pairs = ObjectArrays.concat(this.pairs, pairs, ButtonPair.class);
}
the right side of the thing is fine, but the left side does not designate this.pairsdue to ambiguity. Sorry And the hats go to Google Collections!
Google Collections, unit tests.
String[] result = ObjectArrays.concat(
new String[] { "a", "b" }, new String[] { "c", "d" }, String.class);
assertEquals(String[].class, result.getClass());
assertContentsInOrder(Arrays.asList(result), "a", "b", "c", "d");
, Class<T>, , , .
. , . 100% ? :
import com.google.common.collect.ObjectArrays;
public class ObjectArrayTest
{
public static void main(String[] args)
{
String[] first = new String[] { "Fire", "Earth" };
String[] second = new String[] { "Water", "Air" };
String[] result = ObjectArrays.concat(first, second, String.class);
for (String s : result)
{
System.out.println (s);
}
}
}
, , .
:
public void register(ButtonPair[] pairs) {
pairs = ObjectArrays.concat(this.pairs, pairs, ButtonPair.class);
}
public void register(ButtonPair[] pairs) {
this.pairs = ObjectArrays.concat(this.pairs, pairs, ButtonPair.class);
}
By the way, that’s why in our store we have a different naming convention for method parameters and variables than for instance variables (although not a terrible prefix / suffix for instance variables, for example _someInstanceVar).