overriding

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

Java: How to call super method from inner in-place class

萝らか妹 提交于 2021-02-04 16:52:06
问题 I have base class Foo with method spam and class Bar which overrides spam . I need to call spam of base class in method of some callback object which is defined in-place: public class Foo { public void spam() { // ... } } public class Bar extends Foo { @Override public void spam() { objectWhichRequireCallback(new Callback { @Override public void onCallback() { super.spam(); } }); } } This code is not working because super is related to Callback , not Bar class. Is it possible to call super

Material-Ui theming issue with React components imported from a library

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 13:28:52
问题 I'm facing an issue, and I searched in Google to find answer with no chance. I have created a React / material Ui library, with a lot of components extended from Material UI. This library belongs to a yarn workspace, together with a main app. The library is built with webpack and babel. In the main app, I'm importing these components and try to apply the global theme, created in the main app, using ThemeProvider. It's seems to work as first sight. When the lib component is alone in the page,

Change BaseClass property to readonly in DerivedClass with new and override

▼魔方 西西 提交于 2021-01-29 04:49:54
问题 I have a situation where I want to make normal property to be readonly in derived class with default value. I am using keyword new for that purpose in the following way: public abstract class BaseClass { public virtual string SomeInfo { get; set; } } public class DerivedClass1 : BaseClass { public new string SomeInfo => "ChildInfo1"; // C# 6.0 equivalent of { get { return "ChildInfo1"; } } } It works fine, and new DerivedClass1().SomeInfo cannot be assigned to -- it is readonly. I'm aware

Overriding hashCode() in Java

懵懂的女人 提交于 2021-01-28 02:00:21
问题 I created a class "Book": public class Book { public static int idCount = 1; private int id; private String title; private String author; private String publisher; private int yearOfPublication; private int numOfPages; private Cover cover; ... } And then i need to override the hashCode() and equals() methods. @Override public int hashCode() { int result = id; // !!! result = 31 * result + (title != null ? title.hashCode() : 0); result = 31 * result + (author != null ? author.hashCode() : 0);

R: Passing function arguments to override defaults of inner functions

我只是一个虾纸丫 提交于 2021-01-27 10:38:11
问题 In R, I would like to do something like this: I have a function f1, that has an argument with a default value; k=3. f1 = function(x,k=3){ u=x^2+k u } I then later define a second function, f2 that calls f1. f2 = function(z,s){ s*f1(z) } What's the cleanest way to allow users of f2 to override the default value of k in the inner function f1? One trivial solution is to redefine f2 as: f2 = function(z,s,K){ s*f1(z,K) } However, I feel this might be cumbersome if I'm dealing with a large

Override the properties of an interface in TypeScript

ぐ巨炮叔叔 提交于 2021-01-21 04:11:47
问题 I know that overriding properties of an interface in an extended interface, modifying their types, is forbidden. I'm looking for an alternative solution that would allow me to not copy the contents of the first interface (it's pretty big). Here is below my first naive approach. Given that base interface: interface OrginalInterface { title?: string; text?: string; anotherProperty?: SomeType; // lots of other properties } This interface is defined in a library. I can't modify it (ie. add

How can I access built-in methods of an Object that is overridden?

吃可爱长大的小学妹 提交于 2021-01-04 02:49:23
问题 A webpage is setting a built-in javascript method to null , and I'm trying to find a way to call the overridden methods in a userscript. Consider the following code: // Overriding the native method to something else document.querySelectorAll = null; Now, if I try to execute document.querySelectorAll('#an-example') , I will get the exception Uncaught TypeError: null is not a function . The reason being the method has been changed to null and is no longer accessible. I'm looking for a way to

How can I access built-in methods of an Object that is overridden?

不羁岁月 提交于 2021-01-04 02:48:09
问题 A webpage is setting a built-in javascript method to null , and I'm trying to find a way to call the overridden methods in a userscript. Consider the following code: // Overriding the native method to something else document.querySelectorAll = null; Now, if I try to execute document.querySelectorAll('#an-example') , I will get the exception Uncaught TypeError: null is not a function . The reason being the method has been changed to null and is no longer accessible. I'm looking for a way to

How can I access built-in methods of an Object that is overridden?

瘦欲@ 提交于 2021-01-04 02:47:22
问题 A webpage is setting a built-in javascript method to null , and I'm trying to find a way to call the overridden methods in a userscript. Consider the following code: // Overriding the native method to something else document.querySelectorAll = null; Now, if I try to execute document.querySelectorAll('#an-example') , I will get the exception Uncaught TypeError: null is not a function . The reason being the method has been changed to null and is no longer accessible. I'm looking for a way to