interface

Overriding IEquatable<T> when T is an interface and hashcodes are different between derived types

不羁岁月 提交于 2021-02-19 07:34:08
问题 I have A and B classes both implementing interface I . public interface I { int SomeInt { get; } bool SomeBool { get; } float SomeFloat { get; } } public class A : I { public int SomeInt { get; } public bool SomeBool { get; } public float SomeFloat { get; } private readonly string _someARelatedStuff; // Rest of class... } public class B : I { public int SomeInt { get; } public bool SomeBool { get; } public float SomeFloat { get; } private string readonly _someBRelatedStuff; private double

Overriding IEquatable<T> when T is an interface and hashcodes are different between derived types

﹥>﹥吖頭↗ 提交于 2021-02-19 07:33:44
问题 I have A and B classes both implementing interface I . public interface I { int SomeInt { get; } bool SomeBool { get; } float SomeFloat { get; } } public class A : I { public int SomeInt { get; } public bool SomeBool { get; } public float SomeFloat { get; } private readonly string _someARelatedStuff; // Rest of class... } public class B : I { public int SomeInt { get; } public bool SomeBool { get; } public float SomeFloat { get; } private string readonly _someBRelatedStuff; private double

Indexer named “Item” required by interface but not possible to implement?

心已入冬 提交于 2021-02-19 02:37:20
问题 I'm trying to implement an interface of a class in the ESPRIT api that requires an indexer named "Item." (I'm guessing the interface came from VB.NET but I don't have the source.) Obviously the "Item[index]" indexer is auto-generated by the compiler by default but I'm getting the following errors: I realize [System.Runtime.CompilerServices.IndexerName("Item")] is redundant; it's simply there to demonstrate explicitly that Item is generated and the error remains. Attempting to implement public

Java interface methods never used

半城伤御伤魂 提交于 2021-02-18 18:14:12
问题 So, I started using interfaces in Java a while ago. I have already created one, and I have a class , that implements that interface. So this is the interface itself: And this is the class that implements the Actor interface : But, as you can see in the first picture, no methods are used, ecxept for create() . The most strange thing is that everything works absolutely fine! Only these underlined words freak me out a bit) 回答1: Your methods are never actually used. This is IntelliJ's way of

Abstract class or interface. Which way is correct?

孤者浪人 提交于 2021-02-17 22:17:38
问题 There are two way for choosing between abstract class or interface. Microsoft solution and Oracle solution: Microsoft, design guideline: Do use abstract (MustInherit in Visual Basic) classes instead of interfaces to decouple the contract from implementations. http://msdn.microsoft.com/en-us/library/ms229013.aspx Oracle, The Java Tutorials: If an abstract class contains only abstract method declarations, it should be declared as an interface instead. http://docs.oracle.com/javase/tutorial/java

Why is adding default methods to interfaces in Java 8 a good design choice and what are the alternatives [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-17 21:16:46
问题 This question already has answers here : Purpose of Default or Defender methods in Java 8 (5 answers) Closed 4 years ago . I am just learning Java, so it is hard for me to access the possible alternatives, and the impact of such a design decision. Java 8 adds the default methods feature to interfaces, which allows interfaces to have an implementation. This allows to extend the existing interfaces with new methods, without breaking the clients, evolving the interface over time in a backward

C# extension method as an interface implementation

懵懂的女人 提交于 2021-02-17 21:10:16
问题 I was wondering if a C# extension method of some class could act as an implementation of interface? What do I have: An iterface: public interface IEventHandler { void Notify(SEvent ev, IEventEmmiter source); } A class that implements it: class Sim : IEventHandler { /*public void Notify(SEvent ev, IEventEmmiter source) { Console.WriteLine("Got notified: " + ev.Name); }*/ } And a class that contains the extension method: public static class ReflectiveEventDispatcher { public static void Notify

C# extension method as an interface implementation

随声附和 提交于 2021-02-17 21:06:10
问题 I was wondering if a C# extension method of some class could act as an implementation of interface? What do I have: An iterface: public interface IEventHandler { void Notify(SEvent ev, IEventEmmiter source); } A class that implements it: class Sim : IEventHandler { /*public void Notify(SEvent ev, IEventEmmiter source) { Console.WriteLine("Got notified: " + ev.Name); }*/ } And a class that contains the extension method: public static class ReflectiveEventDispatcher { public static void Notify

why structure does not implement interface [closed]

耗尽温柔 提交于 2021-02-17 07:16:49
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . Improve this question package main import ( "fmt" ) type UserInput interface { Add(rune) GetValue() string } type NumericInput struct { input string } func (u NumericInput) Add(x interface{}) { switch v := x.(type) { case int: fmt.Println("int:", v) case float64: fmt.Println(

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