permaculture playing cards*
The moose likes Beginning Java and the fly likes Why do i get compilation failure??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why do i get compilation failure???" Watch "Why do i get compilation failure???" New topic
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: 18545
    
  40


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: 18545
    
  40

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why do i get compilation failure???
 
Similar Threads
How to remove common item between 2 ArrayList
Method invocation doubt
Generics
Inheritance
overriding