132k views
5 votes
Which of the following are restrictions of Java generic programming?

I. You cannot use the assignment operator = to assign one generic object to another.
II. You cannot use the == operator to compare two generic objects.
III. You cannot construct arrays of generic types.

A. II only
B. I only
C. III only
D. I and III on

User Safrazik
by
8.1k points

1 Answer

3 votes

Final answer:

The restriction of Java generic programming is that you cannot construct arrays of generic types, making the correct answer 'III only'. The other two statements are incorrect regarding the capabilities of Java generics.

Step-by-step explanation:

The student's question pertains to restrictions of Java generic programming. The correct answer to which of the following are restrictions is C. III only.

In Java generic programming, it is indeed possible to use the assignment operator = to assign one generic object to another, which eliminates statement I.

It is also possible to use the == operator to compare two generic objects, although it is not recommended due to the possibility of comparing references instead of actual contents, thus eliminating statement II.

The restriction in statement III is accurate; you cannot create arrays of a generic type due to type erasure and the way Java implements generics.

User Deividi Cavarzan
by
7.4k points