Downcasting permits an object of a superclass type to be treated as an object of any subclass type.
Questions tagged [downcast]
589 questions
1
vote
1 answer
Downcast using C-style cast when knowing the concrete sub class type
In my project I have a tree of QObjects with different types. Let me give you a simple example which should give you the idea of what I'm talking about. This could be an exemplary QObject tree (not an inheritance diagram but somewhat similar to a…

leemes
- 44,967
- 21
- 135
- 183
1
vote
2 answers
Downcast from superclass: Node to SpecialNode in a linked list
public class Node {
public Node right;
}
public class SpecialNode extends Node {
public String specialLabel;
}
public class Testmain {
public static void main(String[] args) {
Node n1 = new Node();
Node n2 = new Node();
Node n3 = new…

user1665066
- 13
- 2
1
vote
4 answers
Is there an easier/better way to do this, since downcasting isn't allowed in C#?"
Potentially an argumentative topic, but... I really hate that I can't do the following:
class User
{
public string ImageURL {get;set;}
}
class UserUI : User
{
public Brush ImageBrush {get;set;}
}
User user = GetFromUserFromServer();…

Jamona Mican
- 1,574
- 1
- 23
- 54
0
votes
1 answer
Downcast on POCO classes
I have a group of POCO classes:
class ReportBase
{
public string Name { get; set; }
public int CustomerID { get; set; }
}
class PurchaseReport : ReportBase
{
public int NumberOfPurchases { get; set; }
public double TotalPurchases {…

Icerman
- 1,099
- 4
- 14
- 30
0
votes
1 answer
Problem with returning generic type from function
I have a function that searches through a list of trait objects and attempts to find one whose implementor is of a specific type, however the compiler doesent accept the return type.
pub struct GameObject{
pub modules: Vec>,…

Isaksak
- 3
- 1
0
votes
1 answer
DOWNCASTING IN SWIFT
I have an issue using Swift. I have a class:
class ClassA : UIView{
override public init(frame: CGRect) {
super.init(frame: frame)
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
…

EinStyn
- 81
- 7
0
votes
0 answers
Downcasting in ASP.NET Core and MongoDB
I have some BaseFormElementModel class from which other classes are inherited (DateFormElementModel, ShortTextFormElementModel, LongTextFormElementModel, TimeFormElementModel, ...). Those classes have their own unique properties which are…

liphone
- 13
- 3
0
votes
2 answers
Rust generics: list where each element is from the same trait?
I found this question on the Rust users forum : Generics: Can I say "tuple where each element is FromSql". Basically, the questions was to know how do something like that :
trait Foo {}
struct A {}
impl Foo for A {}
struct B {}
impl Foo for B…

antoninhrlt
- 33
- 5
0
votes
0 answers
how downcasting is different from child class object
Through Down casting casting we can access all the members of both child and parent class,
with normal child class object creation also its posssible, why actually **down casting **needed?
(child obj = new child() )
I have explored the downcasting…
0
votes
1 answer
How to store arbitrary struct and recover it as a trait
How can I store an arbitrary struct and recover it as a trait later?
I do not know the trait that will be requested. In some cases the struct might implement the trait but in others it might not.
I tried the object oriented way by storing the struct…

Jonathan C.-R.
- 1
- 3
0
votes
1 answer
Lombok's setter can't be called
package com.example.marketing.semantics.entities;
import com.example.marketing.general.entities.BaseEntity;
import com.example.marketing.general.interfaces.Phraseable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import…

Kifsif
- 3,477
- 10
- 36
- 45
0
votes
0 answers
How to cast ArrayList of user defined data type to another user defined data type which is inherited from first one?
I am trying to convert ArrayList of normalCustomer type to registeredCustomer type.
normalCustomer is of type Customer & registeredCustomer is of type RegCustomer. But Compiler is giving error for the same.
List
- > lr= new…

Utkarsh Pawar
- 1
- 2
0
votes
0 answers
Trouble configuring CKEditor downcast for custom element
I have a custom Media Library which I need to integrate with CKEditor 5. I've managed to write a plugin for adding images and another for adding download links for documents, but I can't get the downcast conversion for the download links to work…
0
votes
0 answers
C++ Down-casting of a vector type
Consider the code snippet below:
#include
class Base {};
class Derived : public Base {};
std:vector> baseVector;
I want to down-cast the vector to vector>
The naive approach would be:
iterating…

Andrey
- 853
- 9
- 27
0
votes
1 answer
Convert derived class to base class in Python
class Option:
order_type: str
pair: str
def __init__(self, pair, order_type) -> None:
self.order_type = order_type
self.pair = pair
class Order(Option):
price: float
quantity: float
def __init__(self,…

yEmreAk.com
- 3,278
- 2
- 18
- 37