generics

Linq To Sql return from function as IQueryable<T>

廉价感情. 提交于 2020-01-21 07:35:06
问题 Ok, I have managed to get the following working public IQueryable getTicketInformation(int ticketID) { var ticketDetails = from tickets in _context.tickets join file in _context.file_objects on tickets.ticket_id equals file.source_id where tickets.ticket_id == ticketID select new { tickets.ticket_id, tickets.title, tickets.care_of_email, file.filename }; return ticketDetails.AsQueryable(); } I went ahead and created my own class (myObject) containing the primitives ticket_id, title, care_of

How to use multiple upper bounds in generics

只愿长相守 提交于 2020-01-21 07:31:48
问题 I have a Interface Foo which has a generic type - public interface Foo<T> { boolean apply(T t); } Having another class Bar which implements this interface but what I want is the generic Type of Bar should be a Collection of type Interface A and B, With the below definition its giving compiler error - public class Bar implements Foo<Collection<? extends A & B>>{ @Override public boolean apply(Collection<? extends A & B> collect){ ... } } Can you suggest the correct way to achieve this? I can

Swift Generics vs Any

♀尐吖头ヾ 提交于 2020-01-21 07:31:45
问题 I read swift documentation in apple site. There is a function swapTwoValues, which swaps two any given values func swapTwoValues1<T>(_ a: inout T, _ b: inout T) { let temporaryA = a a = b b = temporaryA } Now I want to write similar function but instead of using T generic type I want to use Any func swapTwoValues2(_ a: inout Any, _ b: inout Any) { let temporaryA = a a = b b = temporaryA } to call this functions I write var a = 5 var b = 9 swapTwoValues1(&a, &b) swapTwoValues2(&a, &b) I have

Why we cant return List<T> in ASMX web services?

我们两清 提交于 2020-01-21 05:22:11
问题 As developers know we cant return List<T> with web services, we can only return lists with converting them to .ToArray(); I've searched some, but cant get effective answer about Why we cant retun List with web services. Why we must convert them ToArray(); ? 回答1: Web services are supposed to be interoperable with many languages. Nearly all languages have arrays, but only .NET has the specific implementation of List<T> that you're using. 回答2: There is nothing whatsoever preventing you from

What is the difference between the non-generic IEnumerable and the generic IEnumerable<T>?

匆匆过客 提交于 2020-01-21 01:46:06
问题 Sorry for such a vague question, but I have been searching around for the best part of a day, I have read article after article (and many questions here) but just cannot find an easy to understand answer. I (think I) know what IEnumerable is for, but I just can't understand what it means when it is defined with a generic type argument, for example: IEnumerable<int> test = method(); This is just driving me mad! Please put me out of misery and explain what it means? 回答1: An IEnumerable is

Function which generically takes a type and returns the same type

你说的曾经没有我的故事 提交于 2020-01-20 19:42:05
问题 I am having a tough time understanding why the Scala compiler is unhappy about this function definition: def trimNonWordCharacters[T <: Iterable[String]](items: T): T = items map { _.replaceAll("\\W", "") } Here is the REPL output: scala> def trimNonWordCharacters[T <: Iterable[String]](items: T): T = items map { _.replaceAll("\\W", "") } <console>:5: error: type mismatch; found : Iterable[java.lang.String] required: T def trimNonWordCharacters[T <: Iterable[String]](items: T): T = items map

Why is java.util.Map.get(…) not generic? [duplicate]

北城余情 提交于 2020-01-20 07:53:48
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What are the reasons why Map.get(Object key) is not (fully) generic This method and a number of other methods in the Map interface are not generic. Almost anywhere a key value is expected as a parameter, it accepts Object instead, namely remove, get and containsKey. Any idea as to why they made this decision. My assumption is that it was done to support legacy code, but to me, I think that is a weak position.

Why is java.util.Map.get(…) not generic? [duplicate]

99封情书 提交于 2020-01-20 07:53:38
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What are the reasons why Map.get(Object key) is not (fully) generic This method and a number of other methods in the Map interface are not generic. Almost anywhere a key value is expected as a parameter, it accepts Object instead, namely remove, get and containsKey. Any idea as to why they made this decision. My assumption is that it was done to support legacy code, but to me, I think that is a weak position.

Why implicit type inference only works in an assignment?

二次信任 提交于 2020-01-20 06:59:40
问题 I know that using generic in an assignment, a method can implicitly know the type of the return type by looking at the type of the left hand side variable. Example from Google Collection: List<String> l = Lists.newArrayList() My question is why it doesn't work for a method or higher type of inference? Example: List<List<String>> ll = Lists.newArrayList(); ll.put(Lists.newArrayList()); // doesn't work Is this specified in the JLS? If yes, why? If no, then is this a kind of improvement that I

How to create and use a generic bean for enums in f:selectItems?

大憨熊 提交于 2020-01-20 06:52:45
问题 I have generic class with this signature: public abstract class EnumListBean<E extends Enum<E>> { public List<E> getEnumList() { //implementation details } } Currently I have to define a empty subclass in order to access the enumList property for a concrete generic parameter: @ManagedBean @ApplicationScoped public class ItemRarityBean extends EnumListBean<Item.Rarity>{ } This makes its possible to access the property e.g: <f:selectItems value="#{itemRarityBean.enumList}" var="rarity"