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
Java: Can you downcast with a variable?
If I have a few derived classes that have methods that are different than the base class, but similar to each other, can I use a variable to downcast?
for example:
Object derivedClass = baseClass.getChild().getClass();
…

Alan Pauley
- 121
- 1
- 10
1
vote
4 answers
Need help to understand downcasting in java
I'm trying (studying how to) to take advantage of creating abstract class and then subclasses etc.
I have superclass Person:
public abstract class Person {
private String name;
private String type;
public String getType() {
return…

Sergey Lotvin
- 179
- 1
- 14
1
vote
1 answer
when to use three different form of keyword "as" in swift
I'm currently reading "swift programming language 2.1" and is learning how to use the downcasting keyword "as". In the book, there are three different form of as: as, as? and as!. I understand when to use as? and as! but is having trouble figuring…
user5849987
1
vote
2 answers
What make upcasting and downcasting illegal
During lecture some student said this upcasting and downcasting lacks logic and is illegal. Some how the teacher got confused and agreed and said he will review and do the lecture again but i dont know what is wrong with this code and is there a…

Saad Kamran
- 45
- 1
- 9
1
vote
2 answers
Downcasting excecuting parent constructor again in Java?
To understand downcasting, I did the following code.
class Vehicle{
protected int tyres=0;
protected String name="default";
Vehicle(){
}
Vehicle(String aname){
name=aname;
}
//abstract void setTyres(int number);
…

Sum
- 25
- 2
1
vote
4 answers
Downcasting NSManagedObject in Swift Core Data
I have a class that inherits from NSManagedObject. I'm using this object for model data and it's also being persisted.
class Foo: NSManagedObject {
@NSManaged var firstVar: String
@NSManaged var secondVar: String
let entity =…

mbpro
- 2,460
- 3
- 22
- 37
1
vote
1 answer
Override a function in swift that is part of an Obj-C framework class
I am using JSQMessages to build a chat app. I am attempting to turn off the "backspace" in the UITextView element by overriding the deleteBackward() function. I could hack at the JSQ framework core, which I want to avoid, and I've tried forced…

jamesvillarrubia
- 51
- 6
1
vote
6 answers
C++ inheritance question
I have the following problem in application architecture and am willing to solve it (sorry for a lot of text).
I am building a game engine prototype and I have base abstract class AbstractRenderer (I will use C++ syntax, but still the problem is…

Yippie-Ki-Yay
- 22,026
- 26
- 90
- 148
1
vote
2 answers
Unable to modify function parameters within function body
I have a method definition in a swift project:
class func fireGetRequest(urlString: String!, username: String?, password: String?, completionBlock:(NSDictionary)->Void) {
//check if user passed nil userName
if username == nil || password ==…

Devarshi
- 16,440
- 13
- 72
- 125
1
vote
3 answers
Downcasting and Virtual Functions
I was asked this question in an interview and I was unsure of the behaviour in the following case :
class A
{
virtual fun1(){...}
virtual fun2(){...}
};
class B : public A
{
virtual fun1(){...}
virtual fun2(){...}
};
Now…

Vishnu Nair
- 137
- 1
- 5
1
vote
1 answer
C# "implicit" downcast?
Is possible to get the lower class of an inheritance at runtime without explicit cast?
Lets say we have three classes A, B and C.
class A {
int _a;
}
class B : A {
int _b;
}
class C : A {
int _c;
}
And I have a generic method…

André Oliveira
- 68
- 6
1
vote
0 answers
Right way to downcast a unique_ptr of a base class to a derived class
I'm trying to implement an efficient and error free way to perform downcasting of a unique_ptr to a derived class unique_ptr. Reading some posts I found that something like this can work (simple dynamic_cast). However, in this other…

gcswoosh
- 1,279
- 1
- 15
- 31
1
vote
1 answer
Can I pass a subclass instance to a method which accepts superclass instance
I have a setup similar to this. When I try to call execRequest method using java Reflections and in parameterArray pass the subclass instance which is DelRequest I am getting an NoSuchMethodFound Exception
DelRequest delReq=new…

Shahbaz
- 141
- 2
- 7
1
vote
2 answers
Swift range bug with switch-statement
Hello guys I'm new here and right now I'm learning Swift by coding some fancy algorithms, which comes to my mind while reading Apples Swift book.
I was trying to compress (automatically downcast) any IntegerType value.
Here is a little snippet of my…

DevAndArtist
- 4,971
- 1
- 23
- 48
1
vote
1 answer
Downcasting this in an abstract base-class, is there any way to force it?
Is there anyway to force a downcast in the abstract base-class when the derived type is actually known there (due to complicated generics)?
Right now my ugly workaround is to implement an abstract protected property This that simply return this...…

AnorZaken
- 1,916
- 1
- 22
- 34