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
7
votes
2 answers

Dictionary, List and other collections implementation / runtime

I was wondering if there is any good reference (website or even better, a book) where I can find information about the internal implementation of the commonly used collections like Dictionary List Queue Stack etc. By…
zafeiris.m
  • 4,339
  • 5
  • 28
  • 41
6
votes
2 answers

How can I return : where TEnumerable:IEnumerable

Goal: Generic enumerated type to be the same type when returned. Note: This works when the types are entered but I don't understand why they can't be inferred. List then return List IOrderedEnumerable then return…
Michael Puckett II
  • 6,586
  • 5
  • 26
  • 46
6
votes
3 answers

How do you find an element index in a Collection inherited class?

How do you find the index of an element in a Collection inherited class? public class MyCollection : Collection { // implementation here } I tried to use .FindIndex on the collection but no success: int index =…
TheBoyan
  • 6,802
  • 3
  • 45
  • 61
6
votes
4 answers

Stack of generic list gets cleared when pushed list is cleared

I have a little problem when i want to do some operations in c#. I will give you a little example. Stack> steps = new Stack>(); List letterList = new List(); while(true){ …
Berkin
  • 1,565
  • 5
  • 22
  • 48
6
votes
2 answers

JSON generic collection deserialization

I've such DTO classes written in Java: public class AnswersDto { private String uuid; private Set answers; } public class AnswerDto { private String uuid; private AnswerType type; private T value; } class…
Bananan
  • 613
  • 5
  • 19
6
votes
3 answers

How can I reference a super method in a Java class that implements an interface but does not extend another class?

I have a couple of Java classes that extend various implementations of the generic List interface. They simply log anything that is added to the List. The LoggingArrayList is shown below. As the name suggests, it extends ArrayList. The…
6
votes
1 answer

Why doesn't Collections.Generic.Queue have Synchronized method but Collections.Queue has?

System.Collections.Queue class has Queue.Synchronized method which returns a thread-safe Queue implementation. But the generic one, System.Collections.Generic.Queue does not have a Synchronized method. At this point I have two questions in…
ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
6
votes
2 answers

Stack implements ICollection, but has methods from ICollection

I'm trying to create a custom collection based on Stack. When I look at Stack [from metadata] in visual studio, it shows that Stack implements ICollection, which would require it to implement ICollection's CopyTo(Array array, index)…
Thick_propheT
  • 1,003
  • 2
  • 10
  • 29
5
votes
1 answer

How do I avoid compiler warnings when generic type information is unavailable?

I'm using Spring's RestTemplate to make calls against a REST web service. One of these calls is to return a list of objects of a certain type. The RestTemplate methods require that a class argument be supplied to indicate the expected return…
Mike Yockey
  • 4,565
  • 22
  • 41
5
votes
2 answers

Can't understand the Exception when using dynamic with generic collection in .net4

check the code below please: static void Main(string[] args) { IList items = new List(); items.Add(3); items.Add("solid"); dynamic i = new ExpandoObject(); items.Add(i);…
Inside
  • 53
  • 5
5
votes
2 answers

Why wouldn't C# support generics of generics (generics with parameterized types)?

Recently (perhaps of design shortcomings) I faced a regular task when required to have a collection of MyType where T is not fixed (i.e. multiple various generics instantiations throughout one collection). As it's widely proposed (for such cases)…
Alec
  • 1,486
  • 2
  • 14
  • 30
5
votes
1 answer

Collecting a raw stream into a typed collection?

I am calling a library method that returns a raw Stream. I know the type of the elements in the stream and want to collect into a collection with the declared element type. What is the nice, or the not so appalling way of doing it? Minimal…
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
5
votes
1 answer

Swift: Array of equatable generic type

I have been the last days fighting with some issues regarding generics on Swift, and I don't find a way to figure out how to achieve this: I have a class class Store where State is a simple protocol which extends Equatable protocol State:…
Francisco Durdin Garcia
  • 12,540
  • 9
  • 53
  • 95
5
votes
3 answers

Java - Generic types and collections

I'm trying to learn about the use of generic types and I've noticed something weird when I was experimenting with some lines of code. The first piece of code is inside a class named "A": public void func(int k, List list) { list.add(9); …
Mickey
  • 1,405
  • 2
  • 13
  • 33
5
votes
5 answers

Linq and deferred evaluation

When you use LINQ to define an enumerable collection, either by using the LINQ extension methods or by using query operators,the application does not actually build the collection at the time that the LINQ extension method is executed; the…
Green Falcon
  • 818
  • 3
  • 17
  • 48
1 2
3
25 26