inheritance

Getting incompatible error for parent child classes java

蹲街弑〆低调 提交于 2021-02-08 07:34:03
问题 I have a HashMap defined: HashMap<String,ArrayList<Thing>> hashmap = new HashMap<>(); I do need an ArrayList since I want one key to have multiple values. This was the best solution I found for that problem. The Thing class is a parent class for a bunch of other classes. Problem is when I try to add I get an error. hashmap.put(b, world.ports); This is the error: no suitable method found for put(String,ArrayList<SeaPort>) method Map.put(String,ArrayList<Thing>) is not applicable (argument

Getting incompatible error for parent child classes java

久未见 提交于 2021-02-08 07:32:00
问题 I have a HashMap defined: HashMap<String,ArrayList<Thing>> hashmap = new HashMap<>(); I do need an ArrayList since I want one key to have multiple values. This was the best solution I found for that problem. The Thing class is a parent class for a bunch of other classes. Problem is when I try to add I get an error. hashmap.put(b, world.ports); This is the error: no suitable method found for put(String,ArrayList<SeaPort>) method Map.put(String,ArrayList<Thing>) is not applicable (argument

cast a pointer to member function in derived class to a pointer to abstract member function

时光毁灭记忆、已成空白 提交于 2021-02-08 06:42:30
问题 I'm trying to do something that seems like it should be fairly common but I've been unable to find anyone discussing it. this post on stackoverflow is similar to what I'm trying to do, but not quite the same. I have an abstract base class: #ifndef _ABASECLASS_H_ #define _ABASECLASS_H_ using namespace std; #include <iostream> #define CALL_MBR_FUNC(object, ptr_to_mem_func) ((object).*(ptr_to_mem_func)) class aBaseClass { public: typedef void (aBaseClass::*aBaseClass_mem_func)(); int A; int B;

cast a pointer to member function in derived class to a pointer to abstract member function

╄→гoц情女王★ 提交于 2021-02-08 06:41:21
问题 I'm trying to do something that seems like it should be fairly common but I've been unable to find anyone discussing it. this post on stackoverflow is similar to what I'm trying to do, but not quite the same. I have an abstract base class: #ifndef _ABASECLASS_H_ #define _ABASECLASS_H_ using namespace std; #include <iostream> #define CALL_MBR_FUNC(object, ptr_to_mem_func) ((object).*(ptr_to_mem_func)) class aBaseClass { public: typedef void (aBaseClass::*aBaseClass_mem_func)(); int A; int B;

How to use protocols for stucts to emulate classes inheritance

扶醉桌前 提交于 2021-02-08 06:38:33
问题 I'm implementing a model: It has structs ClientSummary and ClientDetails ClientDetails struct has all properties of ClientSummary struct + some extra properties Both structs have main initializer init(jsonDictionary: [String: Any]) inits of ClientSummary and ClientDetails share big part of the code There is an extension which will work with shared functionality of those structs. The most straightforward solution which came to my mind is just classic inheritance, but it doesn't work for value

Static variable for each extended class [duplicate]

南笙酒味 提交于 2021-02-08 05:22:22
问题 This question already has answers here : Java and inherited static members [duplicate] (9 answers) Closed 2 years ago . Let's say I have a base/main abstract class: AbstractObject . AbstractObject is extended by two classes: Object1 and Object2 . Those two templates have many different classes extending from them also, for instance, Object3 , Object4 , and Object5 are inheriting from Object1 , and Object6 , Object7 are inheriting from Object2 . I want each separate class ( Object1 , Object2 ,

Polymorphic query in spring data

你。 提交于 2021-02-08 05:17:52
问题 I have one base abstract class. @Entity @Table(name = "P_FLD") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "FLD_DISCRIMINATOR", columnDefinition = "CHAR(3)") abstract public class AbstractPassbookField and some classes that extends it. For example: @Entity @DiscriminatorValue("F") @Table(name = "P_FLD_F") public class PassbookFileField extends AbstractPassbookField and i create repository for base entity public interface PassbookRepository extends

Operator << and inheritance

≡放荡痞女 提交于 2021-02-08 05:01:55
问题 I have the following classes in C++: class Event { //... friend ofstream& operator<<(ofstream& ofs, Event& e); }; class SSHDFailureEvent: public Event { //... friend ofstream& operator<<(ofstream& ofs, SSHDFailureEvent& e); }; The code I want to execute is: main() { Event *e = new SSHDFailureEvent(); ofstream ofs("file"); ofs << *e; } This is a simplification, but what I want to do is write into a file several type of Events in a file. However, instead of using the operator << of

Scala : parameterize a type with one of its inner types

谁说我不能喝 提交于 2021-02-08 04:18:31
问题 I would like to parameterize a type with one of its subclasses. Consider the following: class DataLoader { class Data { /* data specifics to this data loader */ } def getData : Data /* and so on */ } Now I want to make this loader able to asynchronously retrieve data from the network. One of the options is to have it subclass Callable. class DataLoader extends Callable[Data] { class Data { /* ... */ } def call : Data = { ... } } val futureData = executor.submit(new DataLoader) futureData.get

python class factory inherit random parent

久未见 提交于 2021-02-07 14:49:08
问题 I have some code like this: class Person(object): def drive(self, f, t): raise NotImplementedError class John(Person): def drive(self, f, t): print "John drove from %s to %s" % (f,t) class Kyle(Person): def drive(self, f, t): print "Kyle drove from %s to %s" % (f,t) class RandomPerson(Person): # instansiate either John or Kyle, and inherit it. pass class Vehicle(object): pass class Driver(Person, Vehicle): def __init__(self): # instantiate and inherit a RandomPerson somehow pass d1 = Driver()