• 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

Generic Question

 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This Question is from Niko's Mock questions:



This is not legal. Why?

Whether this is legal :



Integer is a sub class of Number. Why we can't put a Integer where we can put a Number?
 
Ranch Hand
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harpreet Singh janda

means anything that is super class of Number or Number class

change
 
Ranch Hand
Posts: 78
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
List<? super Number> could represent List<Number> or List<Object>, where List<? extends Number> means that the given list contains objects of some unknown type which extends the Number class
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kamil Wojcik,

List<? super Number> could represent List<Number> or List<Object>, where List<? extends Number> means that the given list contains objects of some unknown type which extends the Number class



read it Closely,

that is not

which extends the Number


that is

which is extended by Number

that is super class of Number
 
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

Harpreet Singh janda wrote:


This is not legal. Why?

Integer is a sub class of Number. Why we can't put a Integer where we can put a Number?




The compiler is merely doing what you asked for. You stated that the set type is for a wildcard with a lower bound, and then you assigned it a set that don't conform to the bound.

Keep in mind, we are not talking about the elements in the set. We are talking about the type that the set can handle. So, yes, you can add in Integer into a set designed for Numbers, but that doesn't make an integer set and a number set interchangeable.

Henry
 
Anderson gave himself the promotion. So I gave myself 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