| Author |
Why do i get compilation failure???
|
Sweety C Sanford
Greenhorn
Joined: Feb 11, 2009
Posts: 15
|
|
Hi all,
import java.util.ArrayList;
import java.util.List;
class A1 {}
class B1 extends A1 {}
class C1 extends A1 {}
class D1 extends B1 {
List<?> l = new ArrayList<Object>();
List<? extends B1> m = new ArrayList<D1>();
#List<? extends A1> n = new ArrayList<? extends B1>();
}
In the above code the commented line gives compilation failure but it is expected to be successful.Can anyone help me out in this?
Thanks in advance,
Jesu
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
This topic has nothing to do with I/O and streams. Moving topic to Java in General, Beginners.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
In the above code the commented line gives compilation failure but it is expected to be successful.
Why do you think that it must be successful? Wildcards are used with generic reference declarations, so that they can reference many differnt generic types. Wildcards were never allowed during the instantiation of objects.
Henry
|
 |
Sweety C Sanford
Greenhorn
Joined: Feb 11, 2009
Posts: 15
|
|
|
Sorry..Dint Look into the topic...Anyway thanks for moving it.Hope to get an quick reply.
|
 |
Paul Yule
Ranch Hand
Joined: May 12, 2008
Posts: 229
|
|
|
new means it's time to allocate some memory for the actual object. What object would you have 'physically' created if you were the JVM?
|
 |
 |
|
|
subject: Why do i get compilation failure???
|
|
|