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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Generics

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,

I came across a question in the Whizzlab test, whose answer I have found confusing.

According to it this code would compile but with warnings:

public static void main(String[] args) {

List<? extends Object> ll = new LinkedList<? extends Object>();
ll.add("String");
ll.add(4);
ll.add(true);
ll.toString();

}


but this one would compile without warnings:

public static void main(String[] args) {

List<Object> ll = new LinkedList<Object>();
ll.add("String");
ll.add(4);
ll.add(true);
ll.toString();

}


My understanding is that:

List<Object> ll = new LinkedList<Object>();
mean the same thing as

List<? extends Object> ll = new LinkedList<? extends Object>();
but not according to Whizzlab

Could anyone clarify please?

Thank you
Katrin
 
Katrin Perry
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Sorry, the second code extract would cause compile error according to Whizzlab.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Note: You can use code tags to make the forum format your code nicely.
 
Katrin Perry
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks for the suggestion, but this can't be a reason not to answer my question.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Continued here.
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic