FantasticJamieBurns
FantasticJamieBurns

Reputation: 3004

Does Android Java support primitive type parameter for generic types?

Today I was looking at the following piece of Android source code:

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/animation/IntArrayEvaluator.java

The type is declared as:

public class IntArrayEvaluator implements TypeEvaluator<int[]>

My understanding of Java generics is that primitive types and arrays are not supported.

Am I correct in that understanding?

If I am correct is this something unique to Android's implementation of Java?

Upvotes: 1

Views: 199

Answers (3)

Andy Turner
Andy Turner

Reputation: 140319

int[] is a reference type, and so can be used as a generic type parameter; this is not the same thing as the primitive int type. There is nothing peculiar to Android about this.

Upvotes: 1

Paul Boddington
Paul Boddington

Reputation: 37645

No, you are not correct. int[] is allowed as a type parameter in both Android and standard Java. This is because int[] is a reference type. int, on the other hand, is a primitive type and is not allowed as a type parameter in either.

Upvotes: 1

Prashant
Prashant

Reputation: 2614

Arrays are supported because internally one object will be created in Heap for all Primitive array as wrapper type.

but primitive types are not applicable.

Upvotes: 1

Related Questions