Downcasting permits an object of a superclass type to be treated as an object of any subclass type.
Questions tagged [downcast]
589 questions
0
votes
1 answer
Downcasting failing from common interface/abstract class
I have two classes - Expert and Farmer, that both share some common characteristics and thus implement an abstract class User. User implements an interface IUser. In my application initially common fields have been filled out but then the user…

Varun Mathur
- 898
- 8
- 11
0
votes
2 answers
Automatic method selection based on class instance
I have two variants of the same method. I also have an instance of a base class type, but I don't know what specific class it is an instance of. I now want to automatically select the appropriate method depending on the actual type of the object. It…

Pfaeff
- 105
- 7
0
votes
2 answers
get enum raw values from [Any] without downcasting
Say I have 5 different enums of String type, enum1:String, enum2:String ...
I have an array [Any] whose type is one of the 5 enums, is there a way to get the raw values of the array of enums without downcasting it to the specific enum type?

jc127
- 343
- 2
- 13
0
votes
2 answers
How to downcast when it's necessary?
I am facing a downcast issue in my company software and I can't manage to find a workaround. (It's something put in place and I cannot change the whole conception)
I will try to give you the whole context with an example: Basically, we have 2…

rilent
- 659
- 1
- 6
- 22
0
votes
1 answer
C++ QT Casting to child classes for items in a QList
I have a QList of type PrintableObject* like:
QList drawables;
This list contains objects of type PrintableX which are subclasses of PrintableObject inserted like:
drawables += &PrintableLine( x, y, x2, y2 );
After this I use the…

Zhigalin - Reinstate CMs
- 746
- 1
- 9
- 33
0
votes
2 answers
C# Down-casting question
Is it valid and legal and to down-cast in the following case:
public interface IA {
string Property1 {get;}
}
public class B {
public string Name {get;set;}
}
// class A doesn't have it's own fields, all IA methods/properties are implemented…

a1ex07
- 36,826
- 12
- 90
- 103
0
votes
1 answer
Cant downCast from myCoustomClass
class MyCViewContollerClass:UIViewController{
var button = UIButton()
}
let storyBoard = UIStoryboard()
let viewController = storyBoard.instantiateViewController(withIdentifier: "vc") as! MyCViewContollerClass

Ekramul Hoque
- 672
- 4
- 17
0
votes
4 answers
Javascript downcasting object
I want to know if there is a native way to downcast an object.
I mean, if I have an object like this: person1 = {name: 'Doe', age: 25};
And other like: person2 = {name: ''};
Is there someFunction that can be used to do something like: var person =…

Josue Garcia
- 1
- 1
- 1
0
votes
1 answer
c++ casting to byte (unit8_t) during subtraction won't force underflow like I expect; output is int16_t; why?
Note that byte is an 8-bit type (uint8_t) and unsigned int is a 16-bit type (uint16_t).
The following doesn't produce the results that I expect. I expect it to underflow and the result to always be a uint8_t, but it becomes a signed int (int16_t)…

Gabriel Staples
- 36,492
- 15
- 194
- 265
0
votes
2 answers
Can i call child class method using parent object?
I have created base class animal and child class as cat.
In main, I want to create obj of PARENT class and call the method of child class.
So, is it possible or not?
I have also used instanceOf to just check relationship
public class…
user5089861
0
votes
1 answer
Java Downcasting Reference parameter interface
I writing a fraction calculator project.I'm trying to write the multiply method. And I need to downcast reference parameter FractionInterface to Fraction if I want to use it as SimpleFraction.
Here's the FractionInterface:
public interface…

Leslie Zhou
- 361
- 1
- 3
- 5
0
votes
2 answers
How to cast (Any)? to Int
I am trying to cast a (Any)? value to a Integer. I am retrieving information from Firebase and I want to add the number by something else. That is why the (Any)? value needs to be a Integer. I have this:
let snapshotValues = snapshot.value as?…

Petravd1994
- 893
- 1
- 8
- 24
0
votes
5 answers
C# General inexplicit upcast of instance by type
Could you explain to me.
How i have to resolve simple task below?
class Base{}
class Derived1: Base { void Method(); }
class Derived2: Base { void Method();}
static void Main(string[] args)
{
Base object; //it is just a declaring
if…

Roman Wood
- 23
- 3
0
votes
1 answer
swift 3 downcast to dynamic class
I am trying to create a couple of objects which are dependent one to each other and they mush have a method to downcast directly the concrete class of the other object. Something like this:
protocol aProt
{
var bVar:bProt! { get set…

Pablo Romeu
- 2,113
- 1
- 13
- 15
0
votes
1 answer
c# Covariance Generics on Properties / Generic Access?
public interface IFoo { }
public abstract class IFooDerived : IFoo { }
public class Foo : IFooDerived { }
public interface IBar { }
public abstract class IBarDerived : IBar { }
public class Bar : IBarDerived { }
public interface IExample…

Maitland Marshall
- 388
- 2
- 19