interface

Why can we not use default methods in lambda expressions?

删除回忆录丶 提交于 2019-12-18 10:44:49
问题 I was reading this tutorial on Java 8 where the writer showed the code: interface Formula { double calculate(int a); default double sqrt(int a) { return Math.sqrt(a); } } And then said Default methods cannot be accessed from within lambda expressions. The following code does not compile: Formula formula = (a) -> sqrt( a * 100); But he did not explain why it is not possible. I ran the code, and it gave an error, incompatible types: Formula is not a functional interface` So why is it not

When to use mixins and when to use interfaces in Dart?

橙三吉。 提交于 2019-12-18 10:39:28
问题 I'm very familiar with the concepts of interfaces and abstract classes, but not super familiar with the concepts of mixins . Right now, in Dart, every class A defines an implicit interface, which can be implemented by another class B by using the implements keyword. There's no explicit way of declaring interfaces as, for example, in Java, where an interface contains only unimplemented methods (and eventually static variables). In Dart, since interfaces are defined by classes, the methods of

C# interface static method call with generics

元气小坏坏 提交于 2019-12-18 10:29:06
问题 Is there a simple way to implement this, and if possible without instanciating an object : interface I { static string GetClassName(); } public class Helper { static void PrintClassName<T>() where T : I { Console.WriteLine(T.GetClassName()); } } 回答1: Try an extension method instead: public interface IMyInterface { string GetClassName(); } public static class IMyInterfaceExtensions { public static void PrintClassName<T>( this T input ) where T : IMyInterface { Console.WriteLine(input

How did C#'s lack of multiple inheritance lead to the need for interfaces?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 10:26:42
问题 In The C# Programming Language Krzysztof Cwalina states in an annotation: we explicitly decided not to add support for multiple inheritance [...] the lack of multiple inheritance forced us to add the concept of interfaces, which in turn are responsible for problems with the evolution of the framework, deeper inheritance hierarchies, and many other problems. Interfaces are a core concept to OO programming languages. I don't follow the meaning of "forced us to add the concept of interfaces"

How to decide between an Interface or Base Class for an new implementation?

泄露秘密 提交于 2019-12-18 10:22:11
问题 When it comes to implementation, how should i decide to go for an base type or an Interface ? I tried to work out on few examples but i don't get the complete idea :( Examples on how and why would be greatly appreciated.. 回答1: A base class, abstract or not, can contain implemented members. An interface cannot. If all of your implementations are going to perform similarly, a base class might be the way to go because all of your child classes can share the same implementations of the members on

A difference in style: IDictionary vs Dictionary

筅森魡賤 提交于 2019-12-18 10:13:12
问题 I have a friend who's just getting into .NET development after developing in Java for ages and, after looking at some of his code I notice that he's doing the following quite often: IDictionary<string, MyClass> dictionary = new Dictionary<string, MyClass>(); He's declaring dictionary as the Interface rather than the Class. Typically I would do the following: Dictionary<string, MyClass> dictionary = new Dictionary<string, MyClass>(); I'd only use the IDictionary interface when it's needed (say

extending 'incomplete' types (SWIG)

女生的网名这么多〃 提交于 2019-12-18 09:20:46
问题 I'm looking for a way to extend (i.e. add new members to a type using the %extend directive) a type that is defined in the library file itself while the header files of the library provide only a forward declaration for the type. Treating the type as if its definition is known at compile time, leads to the following warning: Warning 303: %extend defined for an undeclared class [name of the type]. Is anyone aware of a solution or a workaround for this problem? I'm sure there is one, since SWIG

When is ObjectQuery really an IOrderedQueryable?

那年仲夏 提交于 2019-12-18 08:56:41
问题 Applied to entity framework, the extension methods Select() and OrderBy() both return an ObjectQuery , which is defined as: public class ObjectQuery<T> : ObjectQuery, IOrderedQueryable<T>, IQueryable<T>, <... more interfaces> The return type of Select() is IQueryable<T> and that of OrderBy is IOrderedQueryable<T> . So you could say that both return the same type but in a different wrapper. Luckily so, because now we can apply ThenBy after OrderBy was called. Now my problem. Let's say I have

When is ObjectQuery really an IOrderedQueryable?

浪子不回头ぞ 提交于 2019-12-18 08:56:23
问题 Applied to entity framework, the extension methods Select() and OrderBy() both return an ObjectQuery , which is defined as: public class ObjectQuery<T> : ObjectQuery, IOrderedQueryable<T>, IQueryable<T>, <... more interfaces> The return type of Select() is IQueryable<T> and that of OrderBy is IOrderedQueryable<T> . So you could say that both return the same type but in a different wrapper. Luckily so, because now we can apply ThenBy after OrderBy was called. Now my problem. Let's say I have

Plugin symbol as function return

﹥>﹥吖頭↗ 提交于 2019-12-18 08:55:17
问题 I'm running into a Go behaviour which I don't understand. My idea is to import a plugin which implements an interface that is out of both packages. If a struct is returned it works fine, but to be sure it implements the interface, I want to return an interface which fails. Interface definition: package iface type IPlugin interface{ SayHello(string) SayGoodby(string) WhatsYourName() string } The main program looks like this: package main import ( "plugin" "plugin_test/iface" "errors" "fmt" ) /