Java Generics - What's really in a unbounded wildcard?

Is reified. It is simply the only way to refer to a generified type without using the raw form ( List ). In both cases you are simply doing the exact same operation as.

Up vote 2 down vote favorite share g+ share fb share tw.

If I have the following code : public static void main(String args) { List l2 = new ArrayList (); List l3 = l2; test(l2); test(l3); } public static void test(List l) { if (l instanceof List) System.out. Println("true"); } This will print: true true From what I understand, is a reifiable type, which means it has some capture type (whatever that type is) which is available at run time. Questions: a.

In test method, does it know that l2 has integer type (since it has been erased prior to the method call)? How does it translate so that l (from l2) is instanceof List? B.

What about l3? How does it translate that? Java generics link|improve this question edited Oct 17 '11 at 15:49jtahlborn10.4k1612 asked Oct 17 '11 at 15:46yapkm0156229 72% accept rate.

1 java does not have reifiable types, so the test method knows nothing, and instanceof will never know anything about the generic types. – jtahlborn Oct 17 '11 at 15:50 @jtahlborn: (and voter) The JLS disagrees with you?. – Ryan Stewart Oct 17 '11 at 16:38 k, was thinking more about how it applies in the general sense to generics.

I see now that it also refers to the standard types (which are reifiable). The rest of my statement holds though. – jtahlborn Oct 17 '11 at 17:58.

I don't believe the is reified. It is simply the only way to refer to a generified type without using the raw form (List). In both cases you are simply doing the exact same operation as: if (l instanceof List) ... Edit Indeed I have just verified that they generate absolutely identical bytecode whether you use List or List in the instanceof.

But is a reifiable type. It's the only reifiable type for wildcard .. you can check lots of SCJP books. Here's one of the link angelikalanger.com/GenericsFAQ/FAQSectio... – yapkm01 Oct 17 '11 at 16:14 1 @yap: In that article it's saying that is reifiable in the sense that after erasure, no information has been lost about the type of the list (because nothing is known about the type parameter to begin with!

). But it's not reifiable in the sense that that information is actually available for an object at runtime--at runtime, you don't know that it was a List rather than a List or a List. – Mark Peters Oct 17 '11 at 16:34 Understand now.

Thx – yapkm01 Oct 17 '11 at 17:57 The answer provided by Ryan Stewart is more accurate than the answer proided by Mark Peters. Please correct me if I am wrong:-) – Rekha Nov 23 '11 at 5:57.

The unbounded wildcard is reifiable only in that no type information is lost at runtime because there's no type information to lose. As to your questions: a. The test method doesn't know that l2 has Integer type.

To the test method, it's a List containing "something", and that's all. B. There's no "translation".

It's just a list of unbounded type passed as a parameter to a method that takes a list of unbounded type.

Good answer :-) – Rekha Nov 23 '11 at 5:59.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions