File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wild card generic type

 
nitin pokhriyal
Ranch Hand
Posts: 263
  • 0
  • 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
  • 0
  • 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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic