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 6147091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:03:12+00:00 2026-05-23T19:03:12+00:00

Possible Duplicate: Covariance and Contravariance on the same type argument You can declare a

  • 0

Possible Duplicate:
Covariance and Contravariance on the same type argument

You can declare a generic type parameter as covariant by using the out keyword:

interface ICovariant<out R>

You can declare a generic type parameter as contravariant by using the in keyword:

interface IContravariant<in R>

And you can also support both for different type parameters:

interface IVariant<out R, in A>

So why can’t you suport both for a single type parameter?

  • 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-05-23T19:03:13+00:00Added an answer on May 23, 2026 at 7:03 pm

    So why can’t you suport both for a single type parameter?

    Keep in mind that an interface can only be covariant in a type parameter if that type parameter is output-safe and an interface can only be contravariant in a type parameter if that type parameter is input-safe.

    The syntax out T says that T is a covariant type parameter.

    The syntax in T says that T is a contravariant type parameter.

    As T is a covariant type parameter, it is by definition input-unsafe.

    As T is a contravariant type parameter, it is by definition output-unsafe.

    Therefore, T is input-unsafe and output-unsafe.

    Consequently, T is prohibited in input positions, and T is prohibited in output positions.

    Therefore, T can not appear in input positions nor in any output positions on any methods specified by the interface.

    Consequently, T can not be used on the interface at all, and is pointless as a type parameter. Consequently, the language designers prohibit you from even including such a useless type marked as both covariant and contravariant on the interface to avoid the ugly

    interface IFoo<in and out T> { }
    Foo<T> : IFoo<T> { }
    

    and then:

    IFoo<Cat> cat = (IFoo<Animal>)new Foo<Dog>();
    

    (If you need to read up on input-safe and output-safe, see 13.1.3.1 of the language specification.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can we change the device time using an application? is that possible
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Why is my return type meaningless? Hi, I'm confused about a particular
Possible Duplicate: Parse string into argv/argc I'm trying to write a fake shell using
Possible Duplicate: Find out the instance id from within an ec2 machine I am
Possible Duplicate: How can I increment a date by one day in Java? I
Possible Duplicate: Create Generic method constraining T to an Enum Is there any reason
Possible Duplicate: How to draw a rectangle on a java applet using mouse drag
Possible Duplicate: upload a file to server without using a form? I'am able to
Possible Duplicate: Difference between Covariance & Contra-variance I'm trying to understand what covariance and

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.