interface

Do interfaces solve the “deadly diamond of death” issue?

心已入冬 提交于 2019-12-18 17:00:20
问题 Do interfaces solve the deadly diamond of death problem? I don't think so, for example: // A class implementing two interfaces Interface1 and Interface2. // Interface1 has int x=10 and Interface2 has int x = 20 public class MultipleInterface implements Interface1, Interface2{ public void getX(){ System.out.println(x); } } Here we get an ambiguous x . Though interfaces are a good way for solving method ambiguity, I guess they fail in the case of variables? Am I correct? If I am missing

Set an interface to nil in Golang

喜欢而已 提交于 2019-12-18 16:59:06
问题 I'm trying to set an internal value of an interface to nil something like the following : typ := &TYP{InternalState: "filled"} setNil(typ) fmt.Printf("Expecting that %v to be nil", typ) And I need to know how to implement the setNil(typ interface{}) method. For more details see this code in play.golang.org. 回答1: The thing is you don't have an interface value. You have a pointer value, a pointer to a concrete type. That is not the same as an interface value. If you want to change the value of

Set an interface to nil in Golang

こ雲淡風輕ζ 提交于 2019-12-18 16:59:04
问题 I'm trying to set an internal value of an interface to nil something like the following : typ := &TYP{InternalState: "filled"} setNil(typ) fmt.Printf("Expecting that %v to be nil", typ) And I need to know how to implement the setNil(typ interface{}) method. For more details see this code in play.golang.org. 回答1: The thing is you don't have an interface value. You have a pointer value, a pointer to a concrete type. That is not the same as an interface value. If you want to change the value of

WCF and Interface Inheritance - Is this a terrible thing to do?

倖福魔咒の 提交于 2019-12-18 16:57:14
问题 My application has 2 "services", let's say one is a basic (integer) calculator, and one is a floating point calculator. I express these as interfaces like so: public interface IBasicCalculator { int Add( int a, int b ); } public interface IFloatingPointCalculator { double Add( double a, double b ); } I want to expose these via WCF. Unfortunately WCF seems to be very tightly tied to the notion that every possible operation you want to expose must go through one single service interface -- you

Can you instantiate an Interface in Java [duplicate]

烈酒焚心 提交于 2019-12-18 16:54:56
问题 This question already has answers here : Can we create an instance of an interface in Java? [duplicate] (7 answers) Closed 6 years ago . Can you instantiate an Interface in Java I know the quick answer is "no". But there is something I am not understanding well. What is happening here: SharedPreferences is a public Interface : http://developer.android.com/reference/android/content/SharedPreferences.html However we do not use this interface as I have read about in the books, we do not create a

Delphi Rtti for interfaces in a generic context

天涯浪子 提交于 2019-12-18 16:51:02
问题 for a framework I wrote a wrapper which takes any object, interface or record type to explore its properties or fields. The class declaration is as follows: TWrapper<T> = class private FType : TRttiType; FInstance : Pointer; {...} public constructor Create (var Data : T); end; In the constructor I try to get the type information for further processing steps. constructor TWrapper<T>.Create (var Data : T); begin FType := RttiCtx.GetType (TypeInfo (T)); if FType.TypeKind = tkClass then FInstance

In Ruby, what is the equivalent to an interface in C#?

拜拜、爱过 提交于 2019-12-18 14:06:23
问题 I'm currently trying to learn Ruby and I'm trying to understand more about what it offers in terms of encapsulation and contracts. In C# a contract can be defined using an interface. A class which implements the interface must fulfil the terms within the contract by providing an implementation for each method and property (and maybe other things) defined. The individual class that implements an interface can do whatever it needs within the scope of the methods defined by the contract, so long

In Ruby, what is the equivalent to an interface in C#?

淺唱寂寞╮ 提交于 2019-12-18 14:06:06
问题 I'm currently trying to learn Ruby and I'm trying to understand more about what it offers in terms of encapsulation and contracts. In C# a contract can be defined using an interface. A class which implements the interface must fulfil the terms within the contract by providing an implementation for each method and property (and maybe other things) defined. The individual class that implements an interface can do whatever it needs within the scope of the methods defined by the contract, so long

Java 8: virtual extension methods vs abstract class

☆樱花仙子☆ 提交于 2019-12-18 13:55:12
问题 I'm looking at the new virtual extension methods in Java 8 interfaces: public interface MyInterface { default String myMethod() { return "myImplementation"; } } I get their purpose in allowing an interface to evolve over time, and the multiple inheritance bit, but they look awfully like an abstract class to me. If you're doing new work are abstract classes prefered over extension methods to provide implementation to an "interface" or are these two approaches conceptually equivalent? 回答1: One

Java - implementing multiple interfaces with same method and different return types

依然范特西╮ 提交于 2019-12-18 13:37:23
问题 Consider the following code: public interface A { public A another(); } public interface B { public B another(); } public interface AB extends A,B { public AB another(); } This leads to a compile error on AB : types B and A are incompatible; both define another(), but with unrelated return types I've seen this SO question, and follow the incompatibility example in the the accepted answer - i.e. public interface C { public void doSomething(); } public interface D { public boolean doSomething()