Questions tagged [downcast]

Downcasting permits an object of a superclass type to be treated as an object of any subclass type.

589 questions
0
votes
3 answers

Upcasting/Downcasting in Java

I am trying to understand upcasting and downcasting in Java and I am confused by the following scenario (about my code, which is below): First - why is it that the code does not compile when I include the line myAnimal.bark();, and Second -…
coolcow
  • 45
  • 6
0
votes
1 answer

Better expression for down-casting and up-casting?

If you know the difference between upcasting and downcasting, then you still can get it wrong because you can only make an educated guess about how the inventor of these names paints his inheritance trees. In computing science trees grow into the…
Patrick Fromberg
  • 1,313
  • 11
  • 37
0
votes
2 answers

Does an object lose its attributes value after Upcasting and then Downcasting?

I have upcasted Model2 instance in the following code to Object class and then downcasted back to the class - Model2 in the test method of Model1 class. But thenUov its attribute value after downcasting is showing null. Is this expected for the…
user93726
  • 683
  • 1
  • 9
  • 22
0
votes
0 answers

Downcast using static_cast/dynamic_cast is invalid

I'm trying to assign the address that a base class smart pointer is pointing to to a raw pointer of a derived class. The size of data that the base class pointer is pointing to is the same of the derived class. Directory is the derived class and…
0
votes
1 answer

Entity Framework two tables with identical objects

I have two tables that have identical properties, for example: DbSet Students; DbSet Teachers; However Entity Framework does not allow the same class to be used for different tables. So, instead I use: DbSet
Brian Rice
  • 3,107
  • 1
  • 35
  • 53
0
votes
0 answers

How to cast this parcelable array list to an array list of cholesterol monitors which implements parcelable?

I know downcasting isn't allowed in Java but is there a way to cast an array list of parcelable objects into an array list of cholesterolMonitors which implements parcelable? In one of my abstract classes I have: private ArrayList
Sook Lim
  • 541
  • 6
  • 28
0
votes
1 answer

Pattern to avoid the need for Downcasting/Reflection

Suppose I have two implementations of a base class: public class Base { public string Stringify() { return "I am a member of base class"; } } public class A : Base { public void DoAThing() {...}; } public class B : Base { public void…
Dan Brenner
  • 880
  • 10
  • 23
0
votes
3 answers

Derived Class Pointer Pointing To Base Class Object Using Static_Cast

I have the below piece of code where I have a base class and a derived class. Both base class and derived class are having a function member sharing the same name. In the main(), I have typecasted a base class object to a derived class pointer and…
amit singh
  • 385
  • 1
  • 3
  • 8
0
votes
1 answer

the replacement of converted columns after downcasting doesn't end

I'm working on my first correlation analysis. I've received the data through an excel file, I've imported it as Dataframe (had to pivot it) and now I have a set of almost 3000 rows and 25000 columns. I can't choose a subset from it, as every column…
cribb
  • 21
  • 3
0
votes
4 answers

java: "downcasting" to new object / opposite of slicing

Sorry, i really dont know how to make a headline for that question; maybe there is a name for what im trying to do that i dont know, but i can explain it with some code: Guess you have a class that unfortunately neither has a copy-constructor nor a…
rhavin
  • 1,512
  • 1
  • 12
  • 33
0
votes
0 answers

Tracing an inheritance relationship?

I am trying to trace some code and the relationship between a parent and child class. The parent class has the following definition: public class A implements Comparable { private String owner; public A(String s) { owner = s; } //More…
user10335564
  • 133
  • 3
  • 16
0
votes
1 answer

In java, does repetition of downcasting and upcasting erases data inside subclass?

I realize that upcasting converts subclass to superclass while downcasting does so in opposite way. However, assuming there are different numbers of data types for subclass and superclass, does conversion from subclass->superclass->subclass makes…
Nathan Lee
  • 75
  • 1
  • 3
  • 10
0
votes
1 answer

Upcast ViewControllers for Segues

I have two views, A and B, both inheriting from C. In storyboard, I define a UIViewController as type C. Another view, lets say D, has two segues to C. I want to be able to cast the destination according to the relevant segue: if segue.identifier =…
Ofri
  • 289
  • 5
  • 17
0
votes
0 answers

Core Data, Downcasing Any EXC_BAD_ACCESS (code=1, address=0x0)

I am saving some data I get from an Api with Core Data. Sometimes when I want to save the data an error occurs: Thread 4: EXC_BAD_ACCESS (code=1, address=0x0) in this line: coin.name = ticker.value as? String This is my full function: private…
PaFi
  • 888
  • 1
  • 9
  • 24
0
votes
1 answer

downcasting non-template base to non-type template child class

I have a non-type template class template Derived which derives from some non-template base class Base: class Base { public: double some_value; // Some methods and variables that do not depend on N // I wish to keep…
JorenV
  • 373
  • 2
  • 10