Your code mixes type inference with varargs.
In Java 7, it worked because there was no target type inference: the type of getInteger
call was resolved as just Object
, and then the object was boxed into an Object[]
to fit the varargs call.
With Java 8, T
is inferred from the target type as Object[]
. Since you perform an unchecked cast in getInteger
, this is completely valid, and mandated by the method signature resolution rules, which will consider varargs only if resolution failed without considering it. Here, that was not the case.
Lesson: by performing the unchecked type cast you have waived your right to expect type safety and correctness. You should be prepared to take care of it yourself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…