generics

How to interpret Java generics like <T> T , <T,V> Query<T> , Class<T>?

隐身守侯 提交于 2020-01-13 10:45:12
问题 There is Java API: Morphia class Morphia defines method like: <T> T fromDBObject(Class<T> entityClass, com.mongodb.DBObject dbObject) Can some one explain what <T> T and Class<T> means? Is the method returning a class of type T in a collection? Another API on Inteface DataStore: <T,V> Query<T> find(Class<T> clazz, String property, V value) What <T,V> Query<T> means? Is the method returning an object of type Query that is then surrounded by collection `<T,V>` and `<T>`. This part is very

How do I sort a generic list based on a custom attribute?

空扰寡人 提交于 2020-01-13 10:10:27
问题 I am working in c#.NEt 2.0. I have a class, let's say X with many properties. Each properties has a custom attribute, an interger, which I planned to use to specify its order int he final array. Using reflection I read through all of the properties and group the values and place them into a generic list of properties. This works and I can grab the values. But the plan was SORT the list, based on the custom attribute placed on each property, and finally read out the propery values, already

How do I sort a generic list based on a custom attribute?

情到浓时终转凉″ 提交于 2020-01-13 10:09:23
问题 I am working in c#.NEt 2.0. I have a class, let's say X with many properties. Each properties has a custom attribute, an interger, which I planned to use to specify its order int he final array. Using reflection I read through all of the properties and group the values and place them into a generic list of properties. This works and I can grab the values. But the plan was SORT the list, based on the custom attribute placed on each property, and finally read out the propery values, already

Passing a type as parameter to an attribute

一笑奈何 提交于 2020-01-13 08:30:30
问题 I wrote a somewhat generic deserialization mechanism that allows me to construct objects from a binary file format used by a C++ application. To keep things clean and easy to change, I made a Field class that extends Attribute , is constructed with Field(int offset, string type, int length, int padding) and is applied to the class attributes I wish to deserialize. This is how it looks like : [Field(0x04, "int")] public int ID = 0; [Field(0x08, "string", 0x48)] public string Name = "0"; [Field

Collection of Callable and Generics

折月煮酒 提交于 2020-01-13 07:59:31
问题 I need to launch a bunch of tasks in concurrent threads and retrieve its results. Here is my code: List<Callable<? extends Object>> tasks = new ArrayList<>(); // Adding some tasks whith return different types of results: // Callable<Double>, Callable<String>, Callable<SomeOtherType>, and so on... List<Future<? extends Object>> results = executor.invokeAll( tasks ); But the IDE shows me the next error: no suitable method found for invokeAll(List<Callable<? extends Object>>) method

How implement an interface Generic Method

我怕爱的太早我们不能终老 提交于 2020-01-13 07:16:13
问题 How can I implement, for example, a String type of a non-generic-interface with a generic method ? Here is the interface: // non-generic-class interface I{ public <T> T doI(T t); } 回答1: All the <T> in this interface means is that the type T passed to the method is the same as the type T returned from the method. Implementation requires some use of the symbol T as if it was a class Like public <T> T doI(T t){ Object a = t.getClass().newInstance(); return (T) a; } You can then call it with

Understanding .Net Generics - Bank Domain

[亡魂溺海] 提交于 2020-01-13 06:13:52
问题 This is an attempt to learn Generics (with .Net 4.0). I have been programming for about 4.5 years. Till now I have not used Generics in real time projects. All the time what I have been doing is reading some article about generics and try to understand it. The problem is – most of them try to explains various syntax available with Generics. They explain with examples such as Square, Circle and shapes. Now I have got a chance to design a small application. I would like to use Generics there.

Understanding .Net Generics - Bank Domain

旧街凉风 提交于 2020-01-13 06:13:05
问题 This is an attempt to learn Generics (with .Net 4.0). I have been programming for about 4.5 years. Till now I have not used Generics in real time projects. All the time what I have been doing is reading some article about generics and try to understand it. The problem is – most of them try to explains various syntax available with Generics. They explain with examples such as Square, Circle and shapes. Now I have got a chance to design a small application. I would like to use Generics there.

How to abstract the intersection of types in Typescript?

故事扮演 提交于 2020-01-13 06:11:10
问题 I'm new to TypeScript and I'm trying to write a generic function which returns the intersection of two types. I don't I'm quite understanding record types and their intersection very well so I'm probably doing something wrong but here goes... Let's say we have some types like these: type A = { foo: string } var a: A = { foo: 'foo' } type B = { [key: string]: string } var b: B = a interface C { foo: string } var c: C = a type D = { bar: number } var d: D = { bar: 123 } type E = { [key: string]

How to abstract the intersection of types in Typescript?

时间秒杀一切 提交于 2020-01-13 06:10:30
问题 I'm new to TypeScript and I'm trying to write a generic function which returns the intersection of two types. I don't I'm quite understanding record types and their intersection very well so I'm probably doing something wrong but here goes... Let's say we have some types like these: type A = { foo: string } var a: A = { foo: 'foo' } type B = { [key: string]: string } var b: B = a interface C { foo: string } var c: C = a type D = { bar: number } var d: D = { bar: 123 } type E = { [key: string]