interface

Duck typing and (java) interface concept

半城伤御伤魂 提交于 2019-12-31 08:58:14
问题 I just read the Wikipedia article about duck typing, and I feel like I miss an important point about the interface concept I used to in Java: "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck." class Duck: def quack(self): print("Quaaaaaack!") def feathers(self): print("The duck has white and gray feathers.") def swim(self): print("Swim seamlessly in the water") class Person: def quack(self): print("The person imitates a duck.")

Why can't I put a delegate in an interface?

☆樱花仙子☆ 提交于 2019-12-31 08:56:46
问题 Why can't I add a delegate to my interface? 回答1: You can use any of these: public delegate double CustomerDelegate(int test); public interface ITest { EventHandler<EventArgs> MyHandler{get;set;} CustomerDelegate HandlerWithCustomDelegate { get; set; } event EventHandler<EventArgs> MyEvent; } 回答2: A Delegate is just another type, so you don't gain anything by putting it inside the interface. You shouldn't need to create your own delegates. Most of the time you should just use EventHandler,

Modifying struct members through an interface in Go

烈酒焚心 提交于 2019-12-31 07:00:54
问题 I've come to a point in a Go project of mine where I'd like to create multiple subclasses of a base class, and be able to operate on instances of the subclasses through a base class/interface variable (I'm using the word "class" even though the concept doesn't really exist in Go). Here's what it might look like in C++ just to show what I mean: #include <iostream> using namespace std; class Base { public: int x,y; virtual void DoStuff() {}; }; class Thing : public Base { public: void DoStuff()

Using the ComboBoxEditor interface with Custom JComponent, and allow edit, and display the List

别说谁变了你拦得住时间么 提交于 2019-12-31 05:35:10
问题 I was checking the documentation. https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html https://alvinalexander.com/java/jwarehouse/openjdk-8/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java.shtml http://www.java2s.com/Tutorials/Java/javax.swing/ComboBoxEditor/Java_ComboBoxEditor_getEditorComponent_.htm ... and I'm trying to use my Custom ComboBox implementing the interface ComboBoxEditor . Here my complete Code... I hava one JPanel with JComponents ...

How to exclude properties from JsonConvert.PopulateObject that don't exist in some base type or interface?

吃可爱长大的小学妹 提交于 2019-12-31 04:44:05
问题 Is it possible to define options to JsonConvert.PopulateObject to exclude fields given in a json, that does not exists in the target object's interface implementation? public interface IElementWriter { string Name { get; set; } } public interface IElementUpdateWriter : IElementWriter { string FirstName { get; set; } } public interface IElementInsertWriter : IElementWriter { DateTime? CreationDate { get; set; } } public class Element:IElementWriter, IElementInsertWriter, IElementUpdateWriter {

Abstract classes and Multiple Inheritance

吃可爱长大的小学妹 提交于 2019-12-31 03:31:10
问题 We can achieve the same functionality as interfaces by using abstract classes, So why java doesn't allow the following code? abstract class Animals { public abstract void run(); } abstract class Animals1 { public abstract void run1(); } class Dog extends Animals,Animals1 { public void run() {System.out.println("Run method");} public void run1() {System.out.println("Run1 method");} } I know that multiple inheritance can be achieved by using only interfaces but the above code does the same

Does each branch of c11 _Generic generic association's result expressions have to be valid?

喜你入骨 提交于 2019-12-31 03:24:30
问题 I can't seem to pass the arguments to functions expecting different arguments (or to other _Generic macros which implement a subset of the types of the first one). #define DEBUG_PRINT(x,...) _Generic((x), \ debug_print_options *: DEBUG_PRINT_CUSTOM_TYPE(x, __VA_ARGS__), \ default: DEBUG_PRINT_BASIC_TYPE(x, __VA_ARGS__)) #define DEBUG_PRINT_BASIC_TYPE(x,...) debug_print_printf_specifier((#x), (x), TYPE_TO_PRINTF_SPECIFIER(x), __FILE__, __LINE__, _my_func__, &((struct debug_print_options){__VA

How can an anonymous class have arguments?

时光怂恿深爱的人放手 提交于 2019-12-31 03:17:05
问题 I'm not a java guy but I've inherited some code I need to patch up. I pulled the source into netbeans and I'm getting the error: Anonymous class implements interface; cannot have arguments. Here's the code: Executor background = Executors.newSingleThreadExecutor(); Runnable mylookupThread = new Runnable(FilePath, SearchIndex) { public void run() { MainWindow.this.processFile(this.val$FilePath); Thread t = new Thread(new lookupThread(MainWindow.arrFile, true, false, this.val$SearchIndex)); t

Binding an XML node to a Tree view node

夙愿已清 提交于 2019-12-31 02:20:28
问题 I want to browse through XML using a TTreeView. To associate the treeview nodes with the XML nodes with attributes I used the following syntax: var tv: TTreeView; tn1, tn2: TTreeNode; xn: IXMLNode; if xn.AttributeNodes.Count > 0 then tn2 := tv.Items.AddChildObject( tn1, xn.NodeName, @xn ) else tn2 := tv.Items.AddChild( tn1, xn.NodeName ); .. and later in the program: var tv: TTreeView; pxn: ^IXMLNode; i: integer; pxn := tv.Selected.Data; for i := 0 to iXML.AttributeNodes.Count-1 do

Difference between inheritance and polymorphism

懵懂的女人 提交于 2019-12-31 02:19:06
问题 I was studying about polymorphism. I couldn't determine the analogy in Java about these two features. Let's say Animal class is a concrete superclass with Cat and Dog as its subclasses. I know that this is a case of inheritance. But isn't Cat and Dog classes, polymorphs of Animal class? I am well aware of interfaces in Java. I couldn't understand why interfaces are used instead of concrete classes to explain polymorphism. It could be that the whole purpose of creating interface is to create