Skip to content
Advertisement

Tag: inheritance

ClassCastException “Parent cannot be cast to class…are in unnamed module of loader ‘app’ ” with Java Generics and inheritance

I´m currently facing a problem with generics in Java. I need to return a parent instance casted to the child. The sample below shows what I´m trying to achieve. This code does not run through and produces this exception instead: class com.generics.GenericTest$Parent cannot be cast to class com.generics.GenericTest$ChildEntity (com.generics.GenericTest$Parent and com.generics.GenericTest$ChildEntity are in unnamed module of loader ‘app’) java.lang.ClassCastException: class

Lombok with SuperBuilder

I have a Java project that uses Lombok ( a java library that automatically plugs into the editor and build tools ) and this one: but when I do the builder: I got this error: Answer Cannot reproduce. Check to make sure you’re on the latest lombok (currently, 1.18.16), and if that doesn’t solve the issue, check that you’ve accurately

super.a = b instead of super(b)

I’m learning the super keyword and accidentally get this, here’s an example : The usual way to do this as in the tutorials is super(b) to reusing its parent constructor, but what is wrong with super.a = b? Answer When you write your class A like this: you overwrite the default constructor and in the line this.a = a you

Using Inheritance like this is right?

I’m student learning Inheritance in Java. I’m making a program (Bitcoin Mining Game). In the program, there are different kind of digger (Mining Machine): ordinary digger (this only does digging coin), overclock digger (this can dig and can overclock to dig faster) and durability recover digger (this can dig, overclock and recover durability (every digger has durability, durability drops while

Advertisement