Upcasting permits an object of a subclass type to be treated as an object of any superclass type.
Questions tagged [upcasting]
244 questions
1
vote
1 answer
Python C++ bindings type upcast issue
I have a C++ code which depends on a large library (OpenBabel to be concrete) and uses some of its classes as bases for my classes. This library has its own Python bindings created with SWIG. I've built Python bindings with SWIG for my code with…

Oleg Titov
- 1,100
- 1
- 8
- 13
1
vote
1 answer
this expression was expected to have type IDataReader but here has type SqlDataReader
The following code is not casting my return value of SqlDataReader from getReader correctly to IDataReaderin the call to Seq.unfold. What am I doing wrong?
open System.Data
open System.Data.SqlClient
open System.Configuration
type Foo = { id:int;…

Charles Lambert
- 5,042
- 26
- 47
1
vote
5 answers
String to Object typecasting - Difference
What is the difference between.
public class Test {
public static void main(String args[]) {
String toBeCast = "cast this string";
A a = toBeCast; // error - Type mismatch: cannot convert from String to A
Object object =…

Ankur Singhal
- 26,012
- 16
- 82
- 116
1
vote
2 answers
Java passing variable - downcasting
I have a function e.g.
helloworld(list

Rory Lester
- 2,858
- 11
- 49
- 66
1
vote
1 answer
What is the difference between the up-casting and down-casting?
What is the difference between the up-casting and down-casting with respect to primitive datatypes and referenced datatypes.
For example in primitive types we are saying up-casting is going from lower to higher (int to double) and down-casting is…

Dhivakar
- 2,081
- 5
- 15
- 18
1
vote
1 answer
How can I upcast a Python derived class to it's c++ base with Boost Python?
I have a c++ class with a pure virtual function which I wrap in the following way using Boost Python:
class Model {
virtual double Test() = 0;
};
class ModelWrapper : public Model, public boost::python::wrapper {
double Test() {
…

foob
- 1,287
- 2
- 11
- 12
1
vote
1 answer
why upcasting for List objects? Android / Java syntax
I have been reading code from many Android projects recently to gain more understanding. one of the things I see is the difference in two ways that ArrayList are instantiated.
Note these two examples shown here. why do some use example 1, and why…

Kevik
- 9,181
- 19
- 92
- 148
1
vote
2 answers
upcasting confusion while checking instanceof
class Animal
{
}
class Dog extends Animal
{
}
class main
{
public static void main(String args[])
Animal g= new Dog();
System.out.println(g instanceof Dog); // 1st case
System.out.println(g instanceof…

nr5
- 4,228
- 8
- 42
- 82
1
vote
2 answers
Wrong argument type for NSAssert1
This isn't giving me an error but several warnings I'd like to get rid of.
OSErr err = AudioUnitInitialize(toneUnit);
NSAssert1(err == noErr, @"Error initializing unit: %ld", err);
The warning I'm getting is: Format specifies type 'long' but the…
user393964
1
vote
2 answers
Upcasting in Java and two separate object properties
Trying to understand upcasting in Java. Recently observed strange behavior.
Example:
public class A extends B {
public int i = 2;
public void printI() {
System.out.println("print i = " + this.i);
}
public static void…

Oroboros102
- 2,214
- 1
- 27
- 41
0
votes
1 answer
Upcasting class reference after retrieving it through form
Well,
Let's suppose that I have two Model classes:
public class BaseClass{
public Int32 variable {get;set;}
}
public class DerivatedClass : BaseClass{
public Int32 otherVariable {get;set;}
}
And a View with BaseClass type as Model.
If I…

igor.araujo
- 1,007
- 1
- 7
- 15
0
votes
1 answer
Clarifying some relationships between types, upcasting, and classes/interfaces
Everything occurs in Java. I'm not sure to what extent the programming language affects my questions, and I would be interested to know.
Suppose I have a class Animal, and a subclass which extends Animal called Dog. My understanding is that…

Mr. Brown
- 111
- 6
0
votes
2 answers
Populating a list from a class with objects from other classes
I am having the next code arhitecture:
class candybox with arguments flavor and origin which is the parent class for classes: Lindt, Baravelli and ChocoAmor which will have as a plus arguments: height, width(depending of the box)
class CandyBag…

Aled
- 1
0
votes
0 answers
Upcast dynamic trait in Rust
I am facing the following situation in Rust:
trait BaseTrait {
fn do_base_stuff(&self) -> String;
}
trait GenericChildTrait: BaseTrait {}
trait DynamicChildTrait: BaseTrait {}
enum ChildTraitEnum {
Generic(G),
…

arik
- 28,170
- 36
- 100
- 156
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