| Author |
Wild card generic type
|
nitin pokhriyal
Ranch Hand
Joined: May 19, 2005
Posts: 263
|
|
I was going through the tutorials i saw ArrayList<?> coll1 = new ArrayList <?> (); // error will not compile but i am able to compile it. Please advice where i am wrong?
|
 |
Manfred Klug
Ranch Hand
Joined: Jun 04, 2007
Posts: 377
|
|
Originally posted by nitin pokhriyal: but i am able to compile it.
Interesting. For me, compilation fails.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
Please advice where i am wrong?
You're compiling the wrong class ?
|
[My Blog]
All roads lead to JavaRanch
|
 |
nitin pokhriyal
Ranch Hand
Joined: May 19, 2005
Posts: 263
|
|
Strange thing if i am trying to compile it wil Jdeveloper it will compile fine for me but if i try to use jdevelopers jdk in comand prompt i got 1. B.java:8: unexpected type 2. found : ? 3. required: class or interface without bounds 4. ArrayList<?> arr=new ArrayList<?>(); ^
|
 |
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
I don't see anything wrong here! Thanks,
|
cmbhatt
|
 |
nitin pokhriyal
Ranch Hand
Joined: May 19, 2005
Posts: 263
|
|
Chandra bhatt, That is what i am not getting from jdeveloper but when i try to compile from command prompt i got error.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Originally posted by Chandra Bhatt: I don't see anything wrong here! Thanks,
Read this FAQ entry.
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
nitin pokhriyal
Ranch Hand
Joined: May 19, 2005
Posts: 263
|
|
|
that is the reference material i refered but y chandra is not getting error even if i use jdeveloper i am also not getting that error as i explained in my previous post.
|
 |
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
Ooops! I missed that. Thanks Barry It wont compile. While constructing an parameterized object, you must give it a type that is actual object and not wildcard. You can use wildcard parameterized type with ref variable not object type.
|
 |
 |
|
|
subject: Wild card generic type
|
|
|