Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7925475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:18:24+00:00 2026-06-03T18:18:24+00:00

I had 2 classes as below. From my understanding compiler must not complain at

  • 0

I had 2 classes as below. From my understanding compiler must not complain at line 4 (class WildCard) as my parametrized type is (Node? super Number> s0), as object is super to number in parametrized type. but compiler is complaining at 4,8 and 9. why so.

public class Node<E> {

    private E data;

    public void setData(E obj) {
        data = obj;
    }

    public E getData() {
        return data;
    }
}


public class WildCard {


    static void checkIt(Node<? super Number> s0)
    {
        Object object=new Object(); //1
        Number number =1.5; //2
        Integer integer=10; //3

        s0.setData(object); //4
        s0.setData(number); //5
        s0.setData(integer); //6

        object=s0.getData(); //7
        number=s0.getData(); //8
        integer=s0.getData(); //9
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:18:27+00:00Added an answer on June 3, 2026 at 6:18 pm

    The problem is as follows:

    Node<? super Number> means you could pass in any Node with a parameter that is of type Number or a super type, e.g. Object.

    Since you don’t know the exact type of that generic parameter some operations are not allowed.

    Here’s a short breakdown of why some lines compile and some don’t:

    • s0.setData(object); doesn’t compile because you could have a Node<Number> which would not all you to add an arbitrary object
    • s0.setData(number); compiles since Number matches all possible types for the parameter
    • s0.setData(integer); compiles because Integer extends Number and thus the line above applies

    • object=s0.getData(); compiles because any data object extends Object, always

    • number=s0.getData(); doesn’t compile because you could have a Node<Object> and thus the data object might have a different type (e.g. String)
    • integer=s0.getData(); doesn’t compile, same reason as the line above
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like some feedback regarding the IService class listed below. From what I
The below code is a factory class that is delivers objects of type IGraph
I'm a C# developer for the most part. Back in college I had classes
I am starting to get into programming as a hobby, I had several classes
I had a problem working with the image classes in java. I am creating
I learned about fourier transformation in mathematics classes and thought I had understood them.
In NetBeans 6.7.1, I had a Java project in which I renamed some classes.
I had an interface initially as below. public interface testMe { public Set<String> doSomething();
I have two classes and two pages found below: My question is how do
I have two simple POCO classes; I'm trying to get the MyY property below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.