• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why do i get compilation failure???

 
Sweety C Sanford
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This topic has nothing to do with I/O and streams. Moving topic to Java in General, Beginners.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry..Dint Look into the topic...Anyway thanks for moving it.Hope to get an quick reply.
 
Paul Yule
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic