Questions tagged [downcast]

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

589 questions
2
votes
2 answers

Downcasting instance from external Jar

//Class defined in external jar class A{ many methods... public getId() {}; } //I want to extends this class and overwrite single method class MyA extends A{ private int myId; public getId() {return myId}; } void main () { A a =…
user3369398
  • 227
  • 2
  • 9
2
votes
2 answers

casting base class to derived class via reflection

Hi I have to construct an object from an object. Since the base class has more than 50 fields i dont want to do things like //obj1 is an instance of BaseClass DerivedClass obj2 = new…
jit
  • 452
  • 1
  • 7
  • 26
2
votes
3 answers

How can I correctly downcast the pointer from void* to TMemo* in C++Builder2009?

I am writing multi-thread socket chat in C++Builder 2009. It is almost complete in accordance with what I need to do but I have a little problem. I need to pass the TMemo* pointer into CreateThread WinAPI function which upcasts it to void*. I tryed…
chester89
  • 8,328
  • 17
  • 68
  • 113
2
votes
3 answers

Swift View Controller Downcasting

I thought the following would populate my home variable with my HomeViewController var home = self.parentViewController!.parentViewController! as HomeViewController; Instead I get the following compile error 'Use of undeclared type…
Ben_hawk
  • 2,476
  • 7
  • 34
  • 59
2
votes
1 answer

Downcast from AnyObject?

I am a bit puzzled as to what is going on with the code below. I was under the impression that children would be an optional based on node.children (which is of type [AnyObject]) being of type [SKNode] What I am seeing is that children is never nil,…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
2
votes
3 answers

How to downcast array of object type into an normal array?

I planned to convert an ArrayList into an normal array. After that i tried to downcast that object type into a normal array.But its showing that "Cannot convert from Object to int" at line 17. package coll; import java.util.ArrayList; public class…
2
votes
4 answers

Polymorphic Downcasting in c#?

I'm trying to make food for my IAnimals using a FoodFactory and have a large List of Dogs and Foxs etc. Ideally, I would pass in an IAnimal and the FoodFactory would return the right food but I am not sure how to do this. interface IAnimal…
Big AL
  • 421
  • 3
  • 11
2
votes
1 answer

Downcasting Multidimensional Arrays Swift

I am trying to downcast a multidimensional array property which is required by a protocol in a subclass of the protocol conforming class. However currently the compiler is giving me a an error when I do so. The error is: 'DataClass' is not identical…
Jad
  • 413
  • 1
  • 5
  • 11
2
votes
1 answer

Swift: Downcasting to Generic Type in Function Failing

I have a generic function that takes a value of any object and an in-out parameter with type T. I want to set the in-out parameter to the value of the any object by downcasting the value to type T. func genericFunction(value:AnyObject, inout…
Trung
  • 86
  • 5
2
votes
3 answers

How can I avoid Java downcasts?

I currently am working on a project where I have 3 user classes, lets say UserA, UserB, UserC, that inherit from a abstract User class. The program is supposed to emulate a system wish requires users to login and logout. The instances of those users…
user2009400
  • 147
  • 9
2
votes
2 answers

What happens internally when we do downcasting?

I was trying to understand down-casting... Here is what I have tried... class Shape { public: Shape() {} virtual ~Shape() {} virtual void draw(void) { cout << "Shape: Draw Method" << endl; } }; class Circle : public Shape { public: …
StackIT
  • 1,172
  • 2
  • 13
  • 25
2
votes
2 answers

How to implement a generic interface between C++ and Java using SWIG and Downcasts?

I´m writing an application which is intended to run on different platforms. My base library is written in C++ and I´d like to use SWIG for generating platform-specific code (Java/Android, C#/Windows, Objective C/iOS). Here I´m using Message-Objects…
koch.trier
  • 604
  • 8
  • 21
2
votes
2 answers

How to Downcast to an Overloaded Method

I have a slight problem in my code here I think is interesting: foreach(ISceneNode node in (root as IGroupNode)) { PreVisit(node); if (notFound == false) { return node; …
Musicode
  • 661
  • 1
  • 12
  • 29
2
votes
3 answers

How haskell 'downcast' a type interface?

In oop, such as java, we can only downcast a super class into subclass when the type actually is the subclass. But In haskell, we can simply 'downcast' a type class into any instances of that type class. Such as fromInteger which return a Num. From…
code4j
  • 4,208
  • 5
  • 34
  • 51
2
votes
2 answers

Is it really downcasting not possible? It is working fine for me

I know there are already some questions posted related to this same topic, but I have seen different answers so I am quite confused on which answer is correct. On the below link, people mentioned that downcasting is not possible Convert/Cast base…