interface

How do you implement a container for different types in Go? [duplicate]

只谈情不闲聊 提交于 2019-12-11 00:02:10
问题 This question already has answers here : What would generics in Go be? (2 answers) Closed 2 years ago . The following code implements a List of ints in Go: package main import "fmt" type List struct { Head int Tail *List } func tail(list List) *List { return list.Tail } func main() { list := List{Head: 1, Tail: &List{Head: 2, Tail: &List{Head: 3, Tail: nil}}} fmt.Println(tail(list).Head) } Problem is this only works for int . If I wanted a list of strings , I'd need to re-implement every list

Can someone explain the exact use of interfaces in C#?

醉酒当歌 提交于 2019-12-11 00:01:58
问题 Can someone explain the exact use of interfaces in C#? 回答1: Has msdn not been helpful on this? http://msdn.microsoft.com/en-us/library/87d83y5b.aspx 回答2: This has been discussed so many times here in the past that it is hard to pick any one duplicate for this question. To save the time of repeating what has been said before, try this search, and start going through the results. 回答3: Imagine the the situation of having a factory that creates cars. You know that every vehicle has an engine and

Designing fluent builders to create an object graph in C#

谁说我不能喝 提交于 2019-12-10 23:46:54
问题 I am making a first attempt at writing fluent builders in C# so I can simplify the logic for creating object graphs. My first thought was to create a fluent builder for each class, then nest them hierarchically like this: School school = SchoolBuilder.New() .WithName("Whatchamatta U") .AddClass( ClassBuilder.New() .WithName("Arithmetic") .WithClassNumber("101") .AddStudent( StudentBuilder.New() .WithName("John Smith") ) .AddStudent( StudentBuilder.New() .WithName("Jane Smith") ) ) .Save()

How to interate a ArrayList<Class<? extends IMyInterface>>

风流意气都作罢 提交于 2019-12-10 23:24:43
问题 I have an ArrayList<Class<? extends IMyInterface>> classes = new ArrayList<>(); . When I try to iterate it, I get: Incopatible types: Required: java.lang.Class <? extends IMyInterface> Found: IMyInterface My iteration for (IMyInterface iMyInterface : IMyInterface.getMyPluggables()) {} Red code warning highlight (Android Studio) Error:(35, 90) error: incompatible types: Class<? extends IMyInterface> cannot be converted to IMyInterface I would like to ArrayList<Class<? extends IMyInterface>>

Does Go allow specification of an interface for a map with particular key type?

痴心易碎 提交于 2019-12-10 22:45:17
问题 I wrote a function that would return a sorted slice of strings from a map[string]Foo. I'm curious what is the best way to create a generic routine that can return a sorted slice of strings from any type that is a map with strings as keys. Is there a way to do it using an interface specification? For example, is there any way to do something like: type MapWithStringKey interface { <some code here> } To implement the interface above, a type would need strings as keys. I could then write a

android which class provide definition to SharedPreferences interface

Deadly 提交于 2019-12-10 22:38:21
问题 if look at SharedPreferences it clearly shows it's an interface in Android SDK. public interface SharedPreferences Can anyone help me understand it better that which class exactly provides definition to functions of SharedPreferences? 回答1: It is an interface, there's no mistake in android's documentation. As you can see in SharedPreferences's source code too: public interface SharedPreferences { Digging in android's source code, we can see that Activity extends from ContextWrapper public

Implement a single Java class/interface, which references multiple classes

余生长醉 提交于 2019-12-10 22:35:49
问题 Problem Statement : We have multiple class files (~200+), which each implement different methods and some use the methods from each other also to implement their own methods. We wish to call multiple of these class methods (~20-30) in our code and have them deliver functionality like writing to a UI Web page and reading from a web page. As we wish to make this process simple, we want a single class/interface which contains all these multiple class references (~200+), and we just need to

Display template not used for interface

随声附和 提交于 2019-12-10 22:19:21
问题 I'm having a problem with display templates and dealing with interfaces and objects which implement the interface. In the example I have many objects, which I want to be rendered in a fixed way, I decided to create an interface and reference this in the view which I've decided to put into the shared display templates folder. DisplayFor doesn't seam to work for objects passed to it which implement the interface in the view, does any one know a solution to this. Its probably easier to explain

Would this be the correct place to use the java keyword “interface”?

元气小坏坏 提交于 2019-12-10 22:03:00
问题 I'm rather new to Java. After just reading some info on path finding, I read about using an empty class as an " interface ", for an unknown object type. I'm developing a game in Java based on hospital theme. So far, the user can build a reception desk and a GP's office. They are two different types of object, one is a Building and one is a ReceptionDesk . (In my class structure.) My class structure is this: GridObject-->Building GridObject-->Item-->usableItem-->ReceptionDesk. The problem

How to map interface names to different method names?

孤街醉人 提交于 2019-12-10 21:44:24
问题 If I have an object that implements an interface, it maps the interface methods automatically onto the class's methods with the same name and signature by default. Is there any way to override this and map an interface method onto a method with the same signature but a different name? (This could be useful, for example, if I implement two interfaces, both of which have a method with the same name and signature, and I want to be able to do different things with them.) 回答1: It is indeed