Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wild card generic type

 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by nitin pokhriyal:
but i am able to compile it.

Interesting. For me, compilation fails.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please advice where i am wrong?

You're compiling the wrong class ?
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I don't see anything wrong here!


Thanks,
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chandra Bhatt:


I don't see anything wrong here!


Thanks,


Read this FAQ entry.
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic