abstract

Dart pass this as a parameter in a constructor

不羁的心 提交于 2021-02-17 05:58:08
问题 Lets say that I have an abstract class abstract class OnClickHandler { void doA(); void doB(); } I have a class class MyClass { OnClickHandler onClickHandler; MyClass({ this.onClickHandler }) void someFunction() { onClickHandler.doA(); } } And I have a class class Main implements onClickHandler { // This throws me an error MyClass _myClass = MyClass(onClickHandler = this); // <- Invalid reference to 'this' expression @override void doA() {} @override void doB() {} } How can I say that use the

How to make a abstract class with default comments on it?

我与影子孤独终老i 提交于 2021-02-10 14:14:43
问题 I have a superclass with an abstract method I want to provide some comments on the method and if any subclasses inherited this method this comments will come along with it. class MySuper { //some comments protected abstract void myAbstractMethod(); } class MyChild extends MySuper { //some comments @Override public void updateLanguage() { } } 回答1: You need to add proper java-doc comments, than that implementing class will get those. This technique is used in various places inside the jdk too -

why abstract class instantiation isn't runtime error in dart?

为君一笑 提交于 2021-02-09 05:50:09
问题 In many languages if you try to instantiate abstract class you get compile time error. In Dart however, you get warning while compiling and a runtime exception AbstractClassInstantiationError . Why is that? Can someone provide an example, where it's reasonable to compile such code? 回答1: Dart tries to allow you to run your program while you are developing it. That is why many things that are compile time errors in other languages are compile-time warnings and runtime errors in Dart. This

Overriding an abstract property with a derived return type in c#

北慕城南 提交于 2021-02-06 09:41:14
问题 I have four classes. Request, DerivedRequest, Handler, DerivedHandler. The Handler class has a property with the following declaration: public abstract Request request { get; set; } The DerivedHandler needs to override this property so that it returns DerivedRequest instead: public override DerivedRequest request { get; set; } Does anyone have any ideas about how to make this work? 回答1: This isn't really a good way to structure things. Do one of the following 1) Just don't change the return

Overriding an abstract property with a derived return type in c#

倾然丶 夕夏残阳落幕 提交于 2021-02-06 09:41:05
问题 I have four classes. Request, DerivedRequest, Handler, DerivedHandler. The Handler class has a property with the following declaration: public abstract Request request { get; set; } The DerivedHandler needs to override this property so that it returns DerivedRequest instead: public override DerivedRequest request { get; set; } Does anyone have any ideas about how to make this work? 回答1: This isn't really a good way to structure things. Do one of the following 1) Just don't change the return

Python abstract property() “Can't instantiate abstract class [] with abstract methods”, but I did

有些话、适合烂在心里 提交于 2021-01-27 13:19:33
问题 I'm trying to create a base class with a number of abstract python properties, in python 3.7. I tried it one way (see 'start' below) using the @property, @abstractmethod, @property.setter annotations. This worked but it doesn't raise an exception if the subclass doesn't implement a setter. That's the point of using @abstract to me, so that's no good. So I tried doing it another way (see 'end' below) using two @abstractmethod methods and a 'property()', which is not abstract itself but uses

How to pass reference to abstract class - Java

丶灬走出姿态 提交于 2020-07-19 18:30:12
问题 Data data = new Data("path"); //I read data from excel and save. This code is in Main. public abstract class Generator{ public abstract double[][] generate(); //here I need reference - data } public class GeneratorA extends Generator{ public double[][] generate(){ //first implementation - I want to work with data } } public class GeneratorB extends Generator{ public double[][] generate(){ //second implementation - I want to work with data } } What I need is passing reference (data) to

How to fix “CA1810: Initialize reference type static fields inline” with an abstract base…?

风流意气都作罢 提交于 2020-06-27 08:56:33
问题 Here's the simplified parts of code that I have: abstract class DataManager<TValue> { protected static Dictionary<string, TValue> Values; } and then I have: class TextManager : DataManager<string> { static TextManager() { Values = ... // Fill with data } } And, now I'm getting CA1810. I see a few solutions, like making Values public and setting them elsewhere, but I don't like that, or making a static method in TextManager to do the same thing, but is invoked when the program starts, but I

How to fix “CA1810: Initialize reference type static fields inline” with an abstract base…?

浪尽此生 提交于 2020-06-27 08:56:20
问题 Here's the simplified parts of code that I have: abstract class DataManager<TValue> { protected static Dictionary<string, TValue> Values; } and then I have: class TextManager : DataManager<string> { static TextManager() { Values = ... // Fill with data } } And, now I'm getting CA1810. I see a few solutions, like making Values public and setting them elsewhere, but I don't like that, or making a static method in TextManager to do the same thing, but is invoked when the program starts, but I

Java how to optional override method in abstract class?

[亡魂溺海] 提交于 2020-05-25 03:30:23
问题 Let's say we have a base class: public abstract class BaseFragment extends Fragment { ... protected abstract boolean postExec(); ... } And then derive from it to have other class(es) (e.g. Fragment_Movie, Fragment_Weather ...) public class Fragment_Music extends BaseFragment{ @Override protected boolean postExec() { return false; } } However, when adding a new method to the base class: public abstract class BaseFragment extends Fragment { ... protected abstract boolean postExec(); protected