CJCoding With Joseph

Covariant Generic Interface

Make the generic interface IProducer<T> covariant and complete StringProducer. Produce must return the string that was passed to the constructor. The interface must be covariant so that an IProducer<string> can be assigned to an IProducer<object>. Do NOT write a Main method.

The tester creates a StringProducer("hello"), assigns it to an IProducer<object> variable, and prints the produced value:

hello

Expected Output:

hello
Topics:
Interfaces
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.