Questions tagged [generic-collections]

A collection that supports generic typing of its elements

Since java 1.5 (released in 2004), the JDK java.util.Collection interface is generic (typed).

Unless you're using an ancient version of java, the word "generic" in "generic collections" is redundant.

390 questions
5
votes
1 answer

Why does IList implement IEnumerable and ICollection while ICollection itself implements IEnumerable

Why is IList defined like this? public interface IList : ICollection, IEnumerable, IEnumerable public interface ICollection : IEnumerable, IEnumerable public interface IEnumerable : IEnumerable Couldn't it just be public…
5
votes
1 answer

My IEquatable is still using Object.GetHashcode for Dictionary[]

I have something like the following to be a key for a generic dictionary. class IMyClass : IEquatable where T : struct { //etc } class MyClass : IMyClass where T : struct { public bool Equals(IRatingKey other) { …
Alex KeySmith
  • 16,657
  • 11
  • 74
  • 152
5
votes
3 answers

generic data structure in C

Is there any way to create generic data structure in C and use functions in accordance with the stored data type, a structure that has various types of data and for example can be printed according to the stored data. For example, Suppose I wish to…
Peter
  • 53
  • 1
  • 1
  • 5
5
votes
2 answers

How to increase allocated memory ? {The function evaluation was disabled because of an out of memory exception.}

My goal is to load 1.48 million items from XML files into a in memory generic collections dictionary using C# ASP.NET MVC along with ability to render filter lists to views. Right now it works with about 1/2 million items in my dictionary as a…
Bill
  • 915
  • 2
  • 13
  • 23
5
votes
2 answers

Java generics map of Class to a Parser

I have a class that parses a stream of data. Each chunk of data is called a Box. There are many different kinds of Boxes. I want to have a different Parser for each type of box. So basically I need a Registry or something like one that will let…
Lucas
  • 14,227
  • 9
  • 74
  • 124
5
votes
1 answer

Generic collections type test

I'd like to make some operations according to a given collection type (using reflexion), regardless of the generic type. Here is my code: void MyFct(Type a_type) { // Check if it's type of List<> if (a_type.Name == "List`1") …
s0ubap
  • 267
  • 3
  • 8
4
votes
2 answers

How to pass generic class as a generic parameter of method

I have a problem with passing class as a generic param of the method, f.e. I have a simple method: T sendRequest(SomeRestApiRequest request, Class responseClass) which parsing response to specified form. I use them in this way: ItemListJSON…
Jaroslaw K.
  • 5,224
  • 2
  • 39
  • 65
4
votes
4 answers

How to Remove specific field from List

Class structure public class EmployeeDetails { public int Id { get; set; } public string Name { get; set; } public string Exp { get; set; } } List of employee details Id Name Exp -- --------- -------- 1 Bill …
Pradip Talaviya
  • 399
  • 2
  • 8
  • 22
4
votes
2 answers

Take all items except the last ones that satisfy condition?

My specific requirement is that I have an IEnumerable>, and I want to "take" all items in the outer enumeration except any "empty" trailing items, where "empty" means all strings are null/empty or the inner enumeration is empty.…
Kjell Rilbe
  • 1,331
  • 14
  • 39
4
votes
1 answer

How to implement a trait for any iterable type?

I'd like to implement a generic method that's callable on any container or iterator that iterates over a specific type, e.g. &[u32], Vec, (0..99u32), etc. The following code does not compile: trait Foo { fn foo(self); } impl Foo for…
Kornel
  • 97,764
  • 37
  • 219
  • 309
4
votes
3 answers

Using the generic type 'System.Collections.Generic.List' requires 1 type arguments

What does it mean? I used a list of list in ASP.NET MVC and sent them through ViewData of ActionResuls to retrieve it in views. However, when I change it to list of list, it gives me an error of HttpWebException. When I check it inside the immediate…
DELETE me
4
votes
6 answers

Unique classes in generic list

I have a generic class with a generic list in it. I want to ensure that the generic list only contains unique classes. What I have done so far is to compare the class names with reflection (getClass()). But I think that's not a clean solution. Are…
4
votes
2 answers

Creating a class or interface for a complex generic type

I am trying to create an alias for a type of list of list of object. Specifically, I want to shorten all the typing I have to do for this type: IReadOnlyList> My attempt is demonstrated here: using…
arch-imp
  • 217
  • 3
  • 12
4
votes
1 answer

Command line query within Java

I'm accessing a MongoDB and want to reuse typical command line queries also within Java. I know it is possible to use the BasicDBObject, but I want to use command line queries like this: db.MyCollection.find() I tried now using the command() method…
Philipp
  • 4,645
  • 3
  • 47
  • 80
4
votes
1 answer

When using, VS2013, Entity Framework 6 and WebAPI 2, is using a generic repository and UoW framework overkill?

I am re-examining my implementation of the generic unit of work and repository framework. I am using EF6, and VS2013. As such, VS contains WebAPI controller templates that auto-generate WebAPI 2 OData Controller with Actions, using Entity…
ElHaix
  • 12,846
  • 27
  • 115
  • 203