interface

Java interface as reference type? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-11 15:42:53
问题 This question already has answers here : What does it mean to “program to an interface”? (31 answers) Closed last year . Where should I use interface as variable type? I see a lot of people say it's best practice to do so, but every example refers to collections: List<String> list = new ArrayList<>() Does this practice apply mostly to collections? I never saw anyone use interface when declaring i/o streams for example. 回答1: The idea is that you want to hide the actual implementation if it isn

default implementation of an interface that is used as a contained component

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 15:32:46
问题 I have an interface IFoo for which I want to provide a default implementation Foo. Foo can be used as a contained class/component by other classes that implement IFoo. IFoo is used by several classes that mostly implement it by forwarding calls to Foo, but for some methods they may provide their own implementation. Foo needs access to (private) members of the calling class. Passing these members as arguments in method calls is not possible because they are not (and should not be) part of the

Why would interface or type be preferred (if anything) in Typescript under specified condition?

旧街凉风 提交于 2019-12-11 15:11:08
问题 This question is not a dupe of this one, despite the similarites in the title. I'm not asking about the differences but the implications of the differences. Also, I've considered the risk of being opinion-based and voided it by limiting to two viable options and specifying a set of conditions. I asked a question and got a type based answer, which worked. export type Configs = { [key: string]: ButtonConfig | TextBoxConfig | CheckConfig; } When I applied that in my project, the IDE TSLint'ed a

Custom dialog click listener android?

六眼飞鱼酱① 提交于 2019-12-11 14:38:51
问题 I created a custom dialog extending the Dialog class public class CustomAlertDialog extends Dialog implements View.OnClickListener { private TextView tvAlertTitle, tvAlertMessage; private Button butAlertOk, butAlertCancel; private CustomAlertDialog.OnButtonClick onButtonClick; public CustomAlertDialog(Context context) { super(context); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.setContentView(R.layout.layout_alert_dialog); initViews(); } //initialise views private void initViews

Cant set text in TextView - android

两盒软妹~` 提交于 2019-12-11 14:28:00
问题 I checked every topic on stack about textView. I have problems with changing my content in TextView control. public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction super.onCreate(savedInstanceState); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final ViewPager mViewPager; mViewPager = (ViewPager) getActivity().findViewById(R.id.pager); LayoutInflater inflater = getActivity().getLayoutInflater(); builder

Anyone has an alternative to using static methods in a C# interface?

故事扮演 提交于 2019-12-11 14:22:08
问题 I want to implement a collection, whose items need to be tested for emptiness. In case of a reference type, one would test for being null. For value types, one has to implement empty testing, and probably choose a specific value that represents emptyness. My generic collection of T should be usable for both value and reference type values (meaning that Coll<MyCalss> and Coll<int> should both be possible). But I have to test reference and value types differently. Wouldn't it be nice to have an

How to get IPortableDeviceContent interface for given PIDL

纵饮孤独 提交于 2019-12-11 14:22:05
问题 I use SHBrowseForFolder() to select a folder on MTP device. Then I want to copy file from/to there. IPortableDeviceContent interface (from Windows Portable Devices SDK) seems suitable, but how to get it for the object with PIDL, returned from SHBrowseForFolder()? (I asked similar question about obtaining IWMDMStorageControl interface: How to get IWMDMStorageControl interface for given PIDL) 回答1: We can get the displayed name, associated with the PILD from SHBrowseForFolder() in this way:

How to multicast send to all network interfaces?

北城以北 提交于 2019-12-11 13:46:27
问题 Say I have N multicast-capable network interfaces. I am planning to bind N UDP sockets, one to each interface, and send to the same multicast ip/port. Is there a more direct/efficient approach than this? When receiving, I know you can listen over multiple interfaces using the same socket, but sending cannot be done with a single socket, or can it? 回答1: Another aproach is to use IP_MULTICAST_IF to change the interface used for sending multicast on the socket. With this approach, you would call

How to open a PHP file with a JS or HTML Editor in Eclipse

孤街浪徒 提交于 2019-12-11 13:40:08
问题 I normally open a file with it's default editor. Thus a .php file is opened in the default PHP editor and treated like a PHP file. However, often the code in my PHP files contains a lot of JS or HTML. In these cases it would be nice to open such PHP files using a JS or HTML Editor. Right now, this is a pain since I have to click on Open With -> Other and then choose the JS or HTML Editor. Is there a way to add the JS or HTML editor as an option to the Open With menu ? 回答1: Try adding the PHP

C# interface with internal setters

可紊 提交于 2019-12-11 13:39:05
问题 Background : Picture an artwork of a shape where within it is multiple levels of nested shapes. Change of properties e.g. area and length of any of those shape-within-a-shape will cause all the related properties and shapes to change. I have a design pattern which goes like this: I have an object graph called (for discussion sake) "NestedShapes" that has tons of properties which are related to each other, for example, "Area" and "Length". But the graph is designed to be dumb, i.e. given