interface

Declare Interfaces in typings file for JavaScript

佐手、 提交于 2019-12-19 05:56:44
问题 Project Info I'm working on a JavaScript project that utilizes .d.ts files. This is a subsequent question to a question I previously asked, so you can view more information regarding the project here. Problem Although I can normally extract functions from the typings files I can't extract interfaces or namespaces that are either empty or consist purely of interfaces. I have temporarily fixed this problem by creating a const implementation for each interface and using @typeof

Check if a type is an interface

孤者浪人 提交于 2019-12-19 05:22:34
问题 I want to validate a parameter sent to a method, it must be an interface type. What to ask? void (Class<I> interfaceType){ if (thisisnotaninterface){ throw... } } 回答1: Just use Class#isInterface() to check that And seriously, you should be reading the Javadocs before asking here. 回答2: You have got a Class#isInterface() method that does exactly what you want: - if (!interfaceType.isInterface()) { throw... } 来源: https://stackoverflow.com/questions/13582985/check-if-a-type-is-an-interface

Overhead of implementing an interface

别说谁变了你拦得住时间么 提交于 2019-12-19 05:22:26
问题 One of my colleagues told me that implementing interfaces introduces overhead. Is this true? I am not concerned about micro optimizations; I just want to know the deeper details this entails. 回答1: couldn't resist and tested it and it looks like almost no overhead. Participants are: Interface IFoo defining a method class Foo: IFoo implements IFoo class Bar implements the same method as Foo, but no interface involved so i defined Foo realfoo = new Foo(); IFoo ifoo = new Foo(); Bar bar = new Bar

Compiler error on Java generic interface with a List<> method [duplicate]

旧巷老猫 提交于 2019-12-19 05:15:14
问题 This question already has answers here : What is a raw type and why shouldn't we use it? (15 answers) Closed last year . I don't understand the compiler error resulting from the following code. I define a generic interface, see Task, with two methods: U doSomething(String value) and List<Integer> getIDs() . The doSomething() method actually uses the generic type as the type of its return value, but doesn't seem to be causing problems. The getIDs() method returns a List, which is unrelated to

Can't use optional parameters when implementing an interface for a WCF

徘徊边缘 提交于 2019-12-19 05:14:07
问题 In my interface I have declared this. [OperationContract] [WebGet] String GetStuff(String beep, String boop = "too lazy to type"); I implemented it as follows. String GetStuff(String beep, String boop = "too lazy to type") { ... } It compiles and uploads as my WCF service. However, when I used it as a web reference and try to execute the code below, I get the compiler whining and weeping about no method with signature of a single parameter. The last line is the problem. How can I then be too

Alternatives to nested interfaces (not possible in C#)

北城以北 提交于 2019-12-19 05:06:28
问题 I'm using interfaces in this case mostly as a handle to an immutable instance of an object. The problem is that nested interfaces in C# are not allowed. Here is the code: public interface ICountry { ICountryInfo Info { get; } // Nested interface results in error message: // Error 13 'ICountryInfo': interfaces cannot declare types public interface ICountryInfo { int Population { get; } string Note { get; } } } public class Country : ICountry { CountryInfo Info { get; set; } public class

XML Object Deserialization to Interface

左心房为你撑大大i 提交于 2019-12-19 04:49:07
问题 I have two classes SccmAction and TicketAction which both implement interface IDelivery. These classes will be transmitted on a processing queue from which I just want to pull the message and act upon the Deliver method. It seems however that I cannot deserialize to an interface because when I attempt to do so a System.NotSupportedException is thrown. From what I have gathered the XMLSerializer requires a concrete type for serialization. Does this leave me having to create an abstract class

Type Composition: overriding interface types

旧城冷巷雨未停 提交于 2019-12-19 04:00:15
问题 I want to compose a type of another type, but replace one of the fields (which is an interface value) with a fake. The problem I am getting is the underlying field is being used, so I can't seem to override the field. I've demoed the problem here: https://play.golang.org/p/lHGnyjzIS-Y package main import ( "fmt" ) type Printer interface { Print() } type PrinterService struct {} func (ps PrinterService) Print() { fmt.Println("PrinterService") } type Service struct { Client PrinterService }

How can I store different objects in a single list

送分小仙女□ 提交于 2019-12-19 03:46:10
问题 I have two classes an Arc class and a Line class public class Arc { protected double startx; protected double starty; protected double endx; protected double endy; protected double radius; public Arc(){} } public class Line { protected double startx; protected double starty; protected double endx; protected double endy; protected double length; public Line(){} } But I want to store arcs and lines in the same list, so I tried an interface like this public interface Entity { double StartX();

How to avoid reusing identical implementation code with an interface?

流过昼夜 提交于 2019-12-19 03:39:13
问题 First of all, I apologize for "yet another interface question". I thought that this one might be worth asking, though, as it's kind of a strange issue. The project I'm using uses Actionscript 3, but this is more of a general OOP question. Here's the situation: I have a class that already inherits from a base class; it's an object in a videogame. (Let's say it's a spaceship.) In my game, I'd like to have many many many spaceships onscreen, at one time, so I've decided to create an object pool