• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why do i get compilation failure???

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry..Dint Look into the topic...Anyway thanks for moving it.Hope to get an quick reply.
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Let me tell you a story about a man named Jed. He made this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic