polymorphism Questions
4
Solved
Will GetType() return the most derived type when called from the base class?
Example:
public abstract class A
{
private Type GetInfo()
{
return System.Attribute.GetCustomAttributes(this.GetTyp...
Ias asked 25/4, 2011 at 16:37
3
Solved
I would like to know if @JsonTypeInfo annotation can be used for interfaces. I have set of classes which should be serialized and deserialized.
Here is what I'm trying to do. I have two implementa...
Ricciardi asked 3/8, 2012 at 15:9
6
Solved
Why doesn't this work, and what would be a good alternative?
class Grandparent
{
void DoSomething( int number );
};
class Parent : Grandparent
{
};
class Child : Parent
{
void DoSomething()
{...
Dympha asked 15/1, 2011 at 23:30
6
In the context of Java, please explain what a "polymorphic method" is.
Tame asked 5/1, 2011 at 15:17
19
Solved
I'm a bit confused about how Java generics handle inheritance / polymorphism.
Assume the following hierarchy -
Animal (Parent)
Dog - Cat (Children)
So suppose I have a method doSomething(List&l...
Seed asked 30/4, 2010 at 14:39
6
Solved
What are some ways that I can accomplish what Haskell's typeclasses do in OCaml? Basically, I want to write a polymorphic function without writing too much code. The typical way to do polymorphism ...
Justino asked 18/2, 2013 at 10:35
10
Solved
Having a chain of "instanceof" operations is considered a "code smell". The standard answer is "use polymorphism". How would I do it in this case?
There are a number of subclasses of a base class;...
Selfdiscipline asked 7/5, 2010 at 16:37
13
// Cannot change source code
class Base
{
public virtual void Say()
{
Console.WriteLine("Called from Base.");
}
}
// Cannot change source code
class Derived : Base
{
public override void Say(...
Pion asked 24/2, 2010 at 3:7
3
Solved
Suppose following code is given.
class A
{
public:
virtual void someMethod()
{
std::cout << "class A" << std::endl;
}
};
class B : public A
{
public:
...
virtual void someMethod...
Metcalf asked 28/9, 2013 at 10:20
2
Solved
Is there any way how to read polymorphic objects from appsettings.json in a strongly-typed way? Below is a very simplified example of what I need.
I have multiple app components, named Features her...
Prisca asked 2/5, 2019 at 14:41
3
Solved
I'm trying to write an abstract class with some pure virtual binary operators, which should be implemented by the derived class in order to accomplish operator polymorphism. Here's a simplified exa...
Friede asked 21/10, 2012 at 14:10
8
In a java-spring web-app I would like to be able to dynamically inject beans.
For example I have an interface with 2 different implementations:
In my app I'm using some properties file to config...
Classified asked 18/10, 2016 at 9:53
5
Solved
I have a misunderstanding about typecasting in Java language. The problem is ClassCastException. For example, in this code, assuming Animal is the parent class of the Dog class,
Animal animal = ne...
Beautify asked 7/8, 2014 at 22:4
2
Solved
According to What does comparable mean in Elm? comparable is built-in type constraint that can be used to limit type variables to those built-in types that are, well, comparable. The following ques...
Oversubtlety asked 29/6, 2016 at 12:8
7
Solved
I'm reading the tutorial* on how to define many-to-many polymorphic relationships in Laravel but it doesn't show how to save records with this relationship.
In the their example they have
class P...
Walt asked 22/3, 2017 at 11:16
1
I have some classes that I want to (de-)serialize:
public class Top
{
public Top(Sub content) { Content = content; }
public Sub Content { get; init; }
}
public class Sub
{
public Sub(Sub? entr...
Karykaryl asked 9/3, 2022 at 9:17
4
Is there some way to model type hierarchies in Neo4j? If for example I want to build a class hierarchy of cars, I might have a base type of "Car" and then have sub classes that extend that, like "S...
Needlefish asked 21/7, 2014 at 19:24
1
Solved
I am using OpenAPI+OpenAPI-generator with spring boot, and trying to use the schema oneof as follows:
This is the configuration in the requests.yaml file:
...
requestBody:
name: request
required...
Pruchno asked 9/2, 2022 at 9:0
1
Solved
Wanted to implement type safe matrix multiplication in Haskell.
Defined the following:
{-# LANGUAGE TypeFamilies, DataKinds, GADTs #-}
module Vector where
data Nat = Succ Nat | Zero
data Vector (...
Featherston asked 17/2, 2022 at 13:58
11
Solved
A friend and I are studying Java. We were looking at interfaces today and we got into a bit of an discussion about how interfaces are used.
The example code my friend showed me contained this:
I...
Karyolysis asked 10/10, 2011 at 17:29
5
Solved
I'm Java person who just started learning Python. Take this example:
class Person():
def __init__(self, name, phone):
self.name = name
self.phone = phone
class Teenager(Person):
def __init__(...
Trews asked 13/1, 2012 at 16:37
2
Solved
There is this field in a table:
room_id INT NOT NULL CONSTRAINT room_id_ref_room REFERENCES room
I have three 2 tables for two kinds of rooms: standard_room and family_room
How to do something ...
Version asked 29/1, 2015 at 19:2
1
I've noticed that implementing polymorphic recursive types in languages that perform code monomorphization (for e.g: C++, Rust, etc.) is very difficult, if not impossible. This is usually because t...
Treenware asked 25/12, 2021 at 11:53
2
Solved
Consider the following case:
class Base:
...
class Sub(Base):
...
def get_base_instance(*args) -> Base:
...
def do_something_with_sub(instance: Sub):
...
Let's say I'm calling get_base_i...
Concavity asked 17/12, 2021 at 13:23
6
Solved
I understand the motivation for making individual methods of a class sealed/final, but what purpose does completely prohibiting inheritance from the class serve? While allowing overriding of certai...
Janaye asked 30/1, 2010 at 22:16
© 2022 - 2024 — McMap. All rights reserved.