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
0 answers
TypeError: "method is not a function" error when downcasting to a subclass - discrord.js
Please, don't mind my grammar and code mistakes because I am a self-taught coder
I am developing a multi-purpose Discord bot with NodeJS using discord.js and typescript libraries.
When creating the ticket system, and trying to make it as universal…

DeMineArchiver
- 36
- 2
- 6
0
votes
1 answer
Downcast trait to generic type
I have the following 2 traits: Org, Capability.
#![feature(specialization)]
trait Org {}
struct OrgV1 {}
impl Org for OrgV1 {...}
struct OrgV2 {}
impl Org for OrgV2 {...}
trait Capability {}
struct CapV1 {}
impl Capability for CapV1…

Aibek
- 318
- 3
- 11
0
votes
1 answer
DownCasting in generics in java
I am stuck in generics downcasting. Because I learn type erasure. When code compiles all parameterized types are converted to the upper bound if the bound is not defined then it changes to object.
Gen Class
public class Gen
{
T ob;
…

AhmadRaza
- 5
- 6
0
votes
0 answers
Dealing with int dtypes while using .values() in pandas
I have read the documentation:
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.values.html
My df has a mix of strings, objects and int dtypes. I have not found a way to control for using .values() on my df without having to reconvert…

Clay Campbell
- 168
- 13
0
votes
2 answers
Example of useful downcast with static_cast which does not produce undefined behaviour
I am wondering about a short code example of an application of downcast via static_cast, under conditions where there is no undefined behaviour.
I have looked around and I found quite a few texts (posts, Q&A, etc.) referring to fragments of the…

sancho.s ReinstateMonicaCellio
- 14,708
- 20
- 93
- 185
0
votes
0 answers
Downcasting a CompletableFuture's object type - Java/Spring Boot
I have the following classes:
public class AccountDetail {
private String accountNumber;
private Date effectiveDate;
private String status;
// a bunch of other properties
}
public class AccountDetailWithAlerts extends AccountDetail…

apex2022
- 777
- 2
- 8
- 28
0
votes
2 answers
How do I access setter of a subclass without downcasting in my Java code?
I'm pretty new to programming, so please bare with me. I have made a Class Car through composition with an instance variable movable : CarMovable. The CarMovable abstract class is not included here but I have made subclasses from it (since cars…

hi there
- 35
- 3
0
votes
0 answers
How can I cast a Int type value coming from a web service to a String type?
When I receive data from a json I stored inside an array so that I can iterate that array and store each value inside a dictionary type and assign each value using the dict key, the problem is that one of the values is an INT type, if I try to…

Angel Davila
- 75
- 7
0
votes
1 answer
C++ derived-class members after downcasting
I recently learned about upcasting and downcasting in C++. However I came up with a few questions during reading about downcasting. Say I have two classes
class Base {
public:
virtual void foo() {}
};
class Derived : public Base {
public:
…

jleng
- 55
- 1
- 7
0
votes
1 answer
Downcasting an implementation using an interface template
I'm implementing a generic interface that can bridge different implementations of some base class.
The interface utility is written as follows:
// InterfaceUtils.h
//
// Base object class
class IBaseObject {
virtual ~IBaseObject() =…

Martin
- 141
- 1
- 11
0
votes
1 answer
How to avoid downcasting on nested properties (not methods)
I'm coding an API to import data into our software.
As you can see below my models hierarchy is broken down into different types of models (A & B).
Each model :
embed another model : "ImportModel" embed "Production" which embed "Parts"
Ex :…

Daftom
- 1
- 2
0
votes
1 answer
C++ Inheritance & Virtual Functions Where Base Parameters require Replacement with Derived Ones
I have looked high and low for answers to this question - here on this forum and on the general internet. While I have found posts discussing similar topics, I am at a point where I need to make some design choices and am wondering if I am going…

Jason
- 3
- 2
0
votes
2 answers
Is there a way to down cast a struct to its derived one in C++?
Here is my situation:
struct A {
int numberAllChildStructsUse;
}
struct B : A {
std::string strUniqueToB;
}
struct C : A {
std::string strUniqueToC;
}
(in some source file)
B b = thisFunctionReturnsBOrCStructsAsTypeA(int…

dmscs
- 255
- 2
- 12
0
votes
2 answers
Treating a forced downcast to 'SCNView' as optional will never produce 'nil'
Starting with swift 4.2, an error appears. In previous versions the code works fine (swift 3, 4). How to write this code correctly now?
swift4
swift4.2
class GameViewController: UIViewController {
var scene: SCNScene!
var scnView: SCNView!
override…

dmitrique
- 1
- 1
0
votes
1 answer
How to make a drag and drop viewmodifier accept any object
I have created a drag-and-drop viewmodifier that works as expected, but now I would like to make it accept any object. I can add to all the functions, structs, and view-modifiers, but when I try to do add it to my singleton class,…

lmunck
- 505
- 4
- 12