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
4 answers
Downcast from Generic without losing expressiveness
I've something along this lines:
public class Something
{
private IDictionary

Joao
- 7,366
- 4
- 32
- 48
1
vote
1 answer
why should i downcast the context as an instance of the interface?
I just started to learn the fragment API on Android.
I want just to send a message back to my containing activity(I did it). Now I want to clear a misunderstanding about downcasting.
Here is my fragment:
import android.content.Context;
import…

Hamza Belmellouki
- 2,516
- 1
- 18
- 39
1
vote
2 answers
C# Down casting Parent Object to Subclasses
I receive a list of Parent Objects(Devices) and would like to convert each Device Object into a subclass Object. The layout would looks something along the lines of:
public class Device
{
public string FimrwareVersion { get; set; }
public…

John Ucci
- 59
- 5
1
vote
2 answers
How to downcast an array in Java?
I currently have a Tile class that extends a Node class, and want to downcast an array of Nodes to an array of Tiles like so:
class Node {
Node[] neighbours;
private final T value;
}
class Tile extends Node {
public Tile(Point value) {
…

Zac Sanchez
- 71
- 1
- 1
- 8
1
vote
2 answers
upcasting and downcasting in C++
I was trying the idea of casting in C++ using Visual Studio C++ 2010 Express and the use of dynamic_cast.
But somehow, when I run it, an cat object can actually perform dog behaviour.
Seem like Dog d = (Dog)aa; got the compiler confused. Any…

aDeveloper
- 11
- 2
1
vote
1 answer
Rescaling and downcasting a float safely in C++
I am trying to bin a float number R and I want to obtain its weight wt in an unsigned 8 bit integer format:
float R;
float edgeVal = rintf(R); // round to the nearest edge
float dR = R - edgeVal + 0.5f; // distance to the edge with a half-pixel…

Airidas Korolkovas
- 346
- 3
- 12
1
vote
2 answers
down casting for type classes in Scala
I have
trait OptionTransaction {
def data: Data
}
BuyOptionTransaction extends OptionTransaction
SellOptionTransaction extends OptionTransaction
I use these with a Formatter type class to create string representations of various…

Adrian
- 5,603
- 8
- 53
- 85
1
vote
4 answers
Should downcasting be avoided while using a class hierarchy in C++?
Let's say I'm writing an application which works with projects, and exposes different functionality depending on the type of the project. I have a hierarchy of classes for the different types of projects:
class AbstractProject
{
};
class ProjectA :…

neuviemeporte
- 6,310
- 10
- 49
- 78
1
vote
1 answer
Overload a C++ reference cast (downcasting inheritance)
Is is possible to overload a reference cast in C++?
I've got code I can't touch in the format:
void someMethod(Parent& parentReference, ...){
...
Child& child = static_cast(parentReference);
(The class Child inherits directly and…

fatman
- 65
- 6
1
vote
2 answers
Warning when downcasting in Rcpp?
I have an Rcpp function that should take an IntegerVector as input (as toInt). I want to use it on vector of integers, but also on vector of doubles that are just integers (e.g. 1:4 is of type integer but 1:4 + 1 is of type double).
Yet, when this…

F. Privé
- 11,423
- 2
- 27
- 78
1
vote
1 answer
Adding Parcelable interface to a class from external library
I'm using an external library for 3rd party map retrieving in Android.
There's a class that I want to pass through Intent, so I want to make it implement Parcelable.
But the class is from the external library.
What's the best practice to do in…

viz
- 1,247
- 16
- 27
1
vote
3 answers
Detect Object type then cast it accordingly?
My method takes as input an Object. How do i determine it's type, then cast it accordingly?
So for example: binarySearch( Object o );
Inside the binarySearch method, i need a way to determine the type (or class) of Object o. Then i need to cast it…

trusktr
- 44,284
- 53
- 191
- 263
1
vote
1 answer
What is better to use for downcasting boost::polymorphic_pointer_downcast or boost::dynamic_pointer_cast
I'm going to use downcasting in my project in order to cast one boost::shared_ptr<> to another one in class hierarchy. That is my test code where I am using boost/polymorphic_pointer_cast and boost::dynamic_pointer_cast both variant work. But I…

Space Rabbit
- 141
- 2
- 11
1
vote
1 answer
C++11: Avoid downcasting when setting member variables for derived class
Let's say I want to build a Car which has components like Motor, Tire, etc. which are all derived from a "component" base class. Each component has its own states (i.e. motor has RPM, tire has pressure, and so on) as a subclass. A Car class stores…

DayAndNight
- 197
- 2
- 12
1
vote
1 answer
F# Downcasting elements of DataTable
I'm trying to return data from a stored proc on SQL Server 2008 R2. (The stored proc didn't play nicely with Microsoft.FSharp.Data.TypeProviders and I wasted most of the morning going down this seemingly futile path.)
So I get a sequence of tables…

Talmage
- 343
- 1
- 11