generics

ObservableCollection wrapper to cast to a base type

僤鯓⒐⒋嵵緔 提交于 2020-01-15 10:36:07
问题 I have a class called Client , which is a subclass of Configurable . I have an ObservableCollection<Client> which I need to view as an ObservableCollection<Configurable> . This will allow me to databind to the list from some general layout generation code. It must also allow me to clear the list, and to add items to the list. Of course, when adding items to the list it must do a runtime type check to verify the general item ( Configurable ) being added is of the appropriate type ( Client ). I

Is the CPU wasted waiting for keyboard input? (generic) [closed]

雨燕双飞 提交于 2020-01-15 09:16:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I was wandering if there's a way in which the OS doesn't need to cycle ad infinitum waiting for the input from keyboard (or other input device) and if there are any OS using that. I can't believe that we do need to waste cycling just to wait for input, why can't the input do something once is pressed instead of

removing redundant type in Interface

拈花ヽ惹草 提交于 2020-01-15 08:15:12
问题 I have following interfaces public interface IRevision<TRevisionType> { ... } public interface IRevisionLog { ... } public interface IRevisionControl<in TRevision, TLogType,T> where TRevision : IRevision<T> where TLogType : IRevisionLog { ... } This code compiles fine, but I am wondering, is this last one T really needed? When i implement IRevision I will be passing type T, so there is really no need to duplicate type. My demo implementation would be: public class HgRevision : IRevision

Swift check if value is of type array (of any type)

谁都会走 提交于 2020-01-15 07:53:08
问题 How can I check in Swift if a value is an Array. The problem is that an array of type Int can apparently not be casted to an array of type Any . Suppose I have an array myArray of type Int and execute the following: if let array = myArray as? [Any] { return true } it doesn't return true (which surprises me actually). The same thing appears with dictionaries. I want a dictionary of type String, Any (meaning that Any can be any type). How can I check if it is? Thanks in advance. 回答1: Got it

Can generics allow the Java compiler to check the type of keys and values in a map?

橙三吉。 提交于 2020-01-15 06:45:13
问题 I am in a situation where I want to have a map where the keys are an interface class, and the corresponding value is a class which implements that interface. In other words the key and value type is related. My current implementation of the method which adds to the map, and gets an instance of the implementation class looks like: // should be something like Class<T>, Class<? extends T> static Map<Class<?>, Class<?>> map = new HashMap<Class<?>, Class<?>> (); public static <T> void add(Class<T>

Dictionary compatibility of base class vs. subclass values

痴心易碎 提交于 2020-01-15 05:35:16
问题 I have an object hierarchy: MyObject +Variable +etc. (So MyObject is the base class, and Variable is one of the subclasses). I have the dictionaries for the specific types private ConcurrentDictionary<string, Variable> variables = new ConcurrentDictionary<string, Variable>(); etc. and I would like to put all the various lists in one high level dictionary, where I would find all the specific lists: private Dictionary<Type, ConcurrentDictionary<string, MyObject>> objects = new Dictionary<Type,

Implementing generic IComparer in VB

旧城冷巷雨未停 提交于 2020-01-15 05:32:09
问题 I am trying to create a class implementing the generic IComparer of my own class "Stellungen" (which translates to positions, like on a chess or checkers board). This is what I got: Private Class comparer(Of Stellung) Implements System.Collections.Generic.IComparer(Of Stellung) Public Function Compare(x As Stellung, y As Stellung) As Integer Implements System.Collections.Generic.IComparer(Of Stellung).Compare End Function End Class Problem is: inside the function I have no access to any

How to create a list with complex structure inside

↘锁芯ラ 提交于 2020-01-15 05:24:08
问题 I have the following two classes: class Key<T1, T2> {} class Pair<F, S> {} I want to create a map from Key<T1, T2> to List<Pair<T1, T2>> where T1 and T2 are different for each map's entry. I am trying to implement it this way: class KeyToListMap { private Map<Key<?, ?>, List<Pair<?, ?>>> myItems = new HashMap<Key<?, ?>, List<Pair<?, ?>>>(); public<T1, T2> List<Pair<T1, T2>> getList(Key<T1, T2> key) { if (!myItems.containsKey(key)) { myItems.put(key, new ArrayList<Pair<T1, T2>>()); } return

Workaround for generic arrays in java

醉酒当歌 提交于 2020-01-15 04:05:44
问题 I have an assignment and I need to make my own (simple) generic linked list: public class Node<T> { private int key; private T data; private Node<T> nextNode; } But I need to implement a dictionary with a hash table. I wanted to make a list containing Node(s). In case of a conflict (two objects of type disperse to the same node, I simply link them - linked lists). I have to implement this by myself, no outside help (already implemented lists or what ever) How I wanted to do this: public class

Inheriting child-specific method from parent

北慕城南 提交于 2020-01-15 03:57:06
问题 I don't know if this is at all possible, but I was thinking of something in Java: If I have an abstract parent class, I can do this: public ParentClass add(ParentClass a, ParentClass b); If ParentClass then has a child and I want to override this method, the child class will still have a ParentClass add(ParentClass, ParentClass) method. Is there a way to make the parent function derive itself to each child? I don't know if I'm wording it right, but something like this: // ParentClass.java