Unbelievable: Cannot cast from class X to its super class

Unbelievable: Cannot cast from class X to its super class

Content Index :

Unbelievable: Cannot cast from class X to its super class
Tag : development , By : jumpingmattflash
Date : January 10 2021, 01:45 PM

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Cast an object of super class to a sub class - down casting

Tag : java , By : Thomas Gueze
Date : March 29 2020, 07:55 AM
wish of those help A Cat is an Animal.
If I give you an animal (doesn't have to be cat), how would you convert it to a cat?

Why can't I cast super class reference to a subclass that is extending another super class as well?

Tag : cpp , By : kema
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You should avoid using namespace std as std::left and std::right clash with your own definitions.
See http://ideone.com/tMa28j for a working version.

how to cast up to super class when there is an override function in the sub class

Tag : swift , By : eusden
Date : March 29 2020, 07:55 AM
help you fix your problem Because you're overriding the method in a subclass, you're getting dynamic dispatch. The method implementation to call will be based on the dynamic type of the instance that it's called on. Upcasting a Jaguar to a Car only changes the static type of the instance – the dynamic type is still a Jaguar, for that's the type of instance you created.
Therefore upcasting has no bearing whatsoever on the dynamic dispatch of a method – nor should it, as the whole point of dynamic dispatch is to ensure that the correct method implementation for the given instance is called no matter what it's statically typed as.
class Car {
    static func info(for car: Car) {
        print("You've got a Car")

class Jaguar : Car {
    static func info(for jaguar: Jaguar) {
        print("You've got a Jaguar")

let jaguar = Jaguar()
Jaguar.info(for: jaguar) // You've got a Jaguar
Car.info(for: jaguar)    // You've got a Car

let car = jaguar as Car
Jaguar.info(for: car)    // You've got a Car
protocol Car {}

extension Car {
    func info() {
        print("You've got a Car")

class Jaguar : Car {
    func info() {
        print("You've got a Jaguar")

let jaguar = Jaguar()
jaguar.info() // You've got a Jaguar

let car = jaguar as Car
car.info()    // You've got a Car

Cast super class instance returned bya super class method to a subclass instance

Tag : java , By : ffmmjj
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Consider: , Let's address the first part of the question :
public class Super {
    Integer state = 0;

    Super f() {
        Super x = new Super();
        return x;

    protected void incrementState(Super x) {
        x.state = this.state + 1;

public class Sub extends Super {
    Sub f() {
        Sub s = new Sub();
        return s;

Cast fails when casting a sub class equals to the super class

Tag : java , By : jgood
Date : March 29 2020, 07:55 AM
wish of those help Here's a simple example to illustrate. Imagine that PersonOverwritten looked like this:
public class PersonOverwritten extends Person {
    public PersonOverwritten(String nome, int idade) {
    public void pickupSticks() {}
Person superPerson = new Person("marc", 18);        
PersonOverwritten subPerson = (PersonOverwritten) superPerson;
Person person = new PersonOverwritten("marc", 18);        
Related Posts Related QUESTIONS :
  • Not efficiently to use multi-Core CPU for training Doc2vec with gensim
  • webGL gl_Position value saving outside shaders
  • Is it okay for a resolver to have side effects besides resolving the type?
  • Move 32bit register into a 8 bit register
  • Is there a way to update, not overwrite, worker_env for a Dask YarnCluster within a script?
  • Lotus Notes Deployment
  • How Do I Add Active Directory To APIM Using Terraform?
  • How to get the old parameter values in Blazor OnParameterSet?
  • How to debug "ERROR: Could not reach the worker node."?
  • How chain indefinite amount of flatMap operators in Reactor?
  • extract dates and times from string in Redshift
  • How do I make a column of 3 cards match in height in bootstrapVue?
  • how to replace missing values from another column in PySpark?
  • only read last line of text file (C++ Builder)
  • Snakemake --forceall --dag results in mysterius Error: <stdin>: syntax error in line 1 near 'File' from Graphvis
  • How Can I Remove Demo Products From APIM Created With Terraform?
  • How to avoid cloning a big integer in rust
  • Break a row of words into word groups in Hive
  • How can I add a path variable to existing files in an Installshield project converted from MSI
  • Certain languages are not available in postman; is there a way to enable it?
  • Concatenation step of U-Net for unequal number of channels
  • HL Fabric - states, transactions but varied keys
  • How to handle "flood wait" errors when using telethon.sync?
  • Any way to make closure which takes a destructured array?
  • What is the Difference between @PeculiarVentures 's `webcrypto` and `node-webcrypto-ossl`?
  • DWG Sheet Combination failing on AutoDesk Forge
  • karate.log(args) on afterScenario hook is not embedded on surefire json file
  • How do I output latest distinct values of specific fields and all other colums?
  • Clarification on lit-element components and where to browse them
  • Will websockets over HTTP2 also be multiplexed in streams?
  • How to apply switch statement for multi columns in datatables
  • frobot framework - Usage outside testing
  • How do I build against the UCRT with mingw-w64?
  • How to use someClass.android.ts and someClass.ios.ts without errors
  • ADB Connection to Samsung smart tv
  • is there a way to 2 create multiple command files in cypress
  • Best way to filter DBpedia results and return a specific results using SPARQL
  • Is it possible to use unicode combining characters to combine arbitrary characters?
  • Antlr4 extremely simple grammar failing
  • Neighbor of 10 wrong answer?
  • PDFlib - setting stroke and fill opacity (transparency)
  • AWS Lambda + Serverless, where/how to deploy js module that couldn't be bundled?
  • how to place mobile call from PWA
  • How to get connected clients and client certificate in node-opcua server
  • Passing dictionary from one template to another in Helm
  • Kivy. Position of GridLayout inside ScrollView
  • How can I try to place a pending order every X minutes till it's successfull?
  • Is there a way to download the SonarLint report generated in Eclipse IDE?
  • How to Open Port in Windows Firewall using C++ Builder?
  • How to put "OR" operator in Karate API assertion statement
  • Get .model.json as String
  • Proof Process busy on combine_split
  • Does memoization work on smple .select with strings?
  • Check if movement ended
  • Determine If a String Is Present in a List or Map?
  • Shortest_Path Interpretation of Edge Weight
  • Azure Pipelines - What's the difference between a Pipeline artifact and a Build artifact?
  • How to save content of bilion websites found by search engine (how google is doing it)
  • dynamodb index does not return all data
  • Either scp or roles claim need to be present in the token using when application permissions to read sharepoint sites
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com