Skip to content
Advertisement

Tag: polymorphism

Why doesn’t Java automatically access the overridden method?

Given two classes, a parent class and a child class: One has a method called greet(), which is private, and the other one defines a method with the same name, only that it is public. Now, as far as I know, the child’s greet() method doesn’t override the parent’s method, because it ‘hides’ it? (given the fact that private methods

Jackson subtypes – how to specify a default

I want to do something like this with subtypes. I have 3 different types of objects: value can either be a string or an object. The corresponding Java classes are I don’t mind having a discriminator inside Obj1 and Obj2, but there is no place for one when the value is just a string. Is there a way that I

Intellij cannot resolve method even though it is public (Java)

I have googled this a lot, invalidated the cache, and I can’t seem to find an answer. For background, this is a timetabling system using constraint solving. I have a custom class called Period with public methods getStart() and getEnd(). I also have an abstract class Constraint<V, D> and a subclass DemAvailConstratint<Demonstrator, Period>. It is in this subclass (and similarly

Jackson deserialization to concrete polymorphic class

I have following Jackson annotated classes (Kotlin) I try to deserialize JSON that does not contain type property but I provide concrete class so it should not matter I get Missing type id when trying to resolve subtype of … anyway. Is there a way how to tell Jackson to use the type provided in the deserialization and not to

java polymorphism aliasing issue

If there’s 3 classes. A, B and C. class B extends A and class C extends B. class A has equals method: class B has equals method: and class C has euals method: And the main has these code lines: I can’t understand why the equals method of class A is being executed. I know that overloaded methods are bonded

Polymorphism vs Strategy pattern

What is the difference between the Strategy pattern and Polymorphism in Java? I’m confused that whatever is achieved via Strategy Pattern is basically possible by polymorphism. Correct me if I’m wrong in this regard. Please, also provide me example to eradicate my confusion. Answer For me, the link from CKing post and the example in Wikipedia are clear enough, but

Advertisement