covariant Questions

1

I've been recently learning Kotlin, while having some questions with covariant type. The sample code is here. I have Option and Option2 both having a type parameter T and a run extension. I coul...
Kopans asked 19/4, 2019 at 16:50

2

For example I have a Processor base class with a method that returns an Object and takes Object as a parameter. I want to extend it and create a StringProcessor which will return String and take St...
Obstruction asked 21/10, 2017 at 9:19

2

Solved

This code: comboBoxMonth.Items.AddRange(UsageRptConstsAndUtils.months.ToArray()); public static List<String> months = new List<String> { "Jan", "Feb", "Mar", "Apr", "May", ...

3

Solved

I'm trying to implement a Clonable class with the CRTP. However, I need to have abstract class that have a pure virtual clone method, overridden by child classes. To make this happen, I need the cl...
Predetermine asked 15/5, 2015 at 5:22

1

Solved

I've been told by several people that Java allows covariant array subtyping in other words if A is a subtype of B, then A[] is a subtype of B[], but that this is a bad feature because it can lead t...
Intent asked 17/2, 2015 at 20:51

7

I get a compile error when I try to do this: class A { virtual std::vector<A*> test() { /* do something */ }; } class B: public A { virtual std::vector<B*> test() { /* do something ...
Tragedy asked 12/9, 2014 at 17:10

3

Solved

While reading on Covariant Overriding, i find out very strange fact, covariant method overriding is implemented using a bridging technique. it also said that this feature is implemented in java...
Eurypterid asked 6/9, 2013 at 10:24

6

I have the following structure: public interface BarReturn {} public interface FooReturn {} public interface FooBarReturn extends FooReturn, BarReturn {} public interface Foo { FooReturn fooBar...
Tacita asked 14/8, 2011 at 11:18

3

Solved

The following C++ code gives me these errors when compiled: covariant.cpp:32:22: error: invalid covariant return type for ‘virtual Q<B> C::test()’ covariant.cpp:22:22: error: overriding ‘vir...
Hightail asked 22/6, 2013 at 19:11

3

Why does below code prints "1" ? class A { int x = 1; } class B extends A { int x = 2; } class Base { A getObject() { System.out.println("Base"); return new B(); } } public class Covaria...
Aquarius asked 26/5, 2011 at 10:36

4

A virtual function's return type should be the same type that is in base class, or covariant. But why do we have this restriction?
Anatomize asked 28/1, 2011 at 8:47

1

Solved

I know in Java arrays are covariant. So for example: Assume Dog is a subclass of Animal In java the arrays are covariant making: Animal[] a supertype of Dog[] But in java generic collections are ...
Benoite asked 15/11, 2011 at 23:43

3

Solved

I have a subclass that needs to return a subclass of the return type of its parent class. I believe this is called a covariant return type. I am wondering the simplest way to convert from the paren...
Timepleaser asked 19/8, 2011 at 15:9

3

Solved

I'm trying to understand this but I didn't get any appropriate results from searching. In C# 4, I can do public interface IFoo<out T> { } How is this different from public interface IFo...
Stipule asked 28/6, 2011 at 14:59

2

Solved

Since Java 5 we are allowed to have covariant return types. Why doesn't the Java API take advantage of this? Take Graphics2D.create() for instance. Why isn't it overridden to return a Graphics2D o...
Ala asked 20/9, 2010 at 11:48
1

© 2022 - 2024 — McMap. All rights reserved.