Are the two statements equal in Java?
//code 1
Object o1[] = new Class[] {iface};
//code 2
Object o2[] = new Class<?>[] {iface};
Yes, it is effectively the same in this case.
Here
Object o1[] = new Class[] {iface};
you're using a raw type with an unparameterized Class
type.
Here
Object o2[] = new Class<?>[] {iface};
you're using a parameterized Class
type but with a wildcard.
Neither affect what can go into the array.
Since your reference is of type Object[]
, you can't rely on any further type safety anyway, so they are equivalent.
Vulcan, in the comments, brings up a good point that the raw type will create warnings for you during compilation. You might want to avoid that.
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