I tried to look for similar answer but I didn't get/find a solution yet, then I ask directly exposing my case
I have a static function validate
private static void validate(AiNode pNode) {
...
for (AiNode child : pNode.mChildren) {
doValidation(child.mMeshes, child.mMeshes.length, "a", "b");
}
}
}
pNode.mChildren
is an array of AiNode
.
This is my doValidation
private static <T> void doValidation(T[] pArray, int size, String firstName, String secondName) {
// validate all entries
if (size > 0) {
if (pArray == null) {
throw new Error("aiScene." + firstName + " is NULL (aiScene." + secondName + " is " + size + ")");
}
for (int i = 0; i < size; i++) {
if (pArray[i] != null) {
validate(parray[i]);
}
}
}
}
But I keep getting this error
method doValidation in class ValidateDataStructure cannot be applied to given types;
required: T[],int,String,String
found: int[],int,String,String
reason: inferred type does not conform to upper bound(s)
inferred: int
upper bound(s): Object
where T is a type-variable:
T extends Object declared in method <T>doValidation(T[],int,String,String)
----
(Alt-Enter shows hints)
I think it has to do with the fact that arrays of primitive type in java extends Object[], indeed if I switch T[]
to T
it works, but then I cannot loop it anymore... I don't know how to solve it or which solutions applies best to my case.
The idea is to have different validate(T[] array)
based on the array T
type
Your array is int[]
, not Integer[]
. To convert it to Integer[]
use
for (AiNode child : pNode.mChildren) {
Integer[] meshes = Arrays.stream(child.mMeshes).boxed().toArray(Integer::new);
doValidation(meshes, child.mMeshes.length, "a", "b");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With