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
2
votes
1 answer

instantiation of a generic tree pointer ada

I try to build a generic binary search tree module in Ada, and the tree will be the generic parameter, so, i do that: -- Spécification du module ABR. -- Mettre T_ABR comme un pointeur générique. Generic type T_Noeud(<>); type T_ABR is…
user11110733
2
votes
0 answers

How to create a mutable list with a type retrieved via reflections

I am currently working on a deserialization problem which requires the population of a mutable list in kotlin with a generic type obtained via reflections. Specifically, I am provided with a function variable, and I need to make the mutable list's…
2
votes
2 answers

How to add value to list when using object initializer?

private PostDto MapIntegration(IntDto integ) { return new PostDto { prop1 = "7", prop2 = "10", prop3 = true, prop4 = "EA Test", product_list.Add(integ) // ERROR This says the name product_list does not…
Roxy'Pro
  • 4,216
  • 9
  • 40
  • 102
2
votes
2 answers

Creating a generic method in C# through specific where clause

I want to create some generic methods like code below: public async Task Get(string url) where T : IBaseModel, IList Obviously I want to support enumerable collection and also the single object which drived from IBaseModel…
Saman Gholami
  • 3,416
  • 7
  • 30
  • 71
2
votes
2 answers

Lodash how to assign specific property of object during comparing two collections of different objects

I have one question. Is there any function in lodash library which is going to provide me the method for comparing each object in both collections by specific property and if the condition is fulfilled then creating another object? example: a)…
aggre1234
  • 73
  • 6
2
votes
2 answers

C# List Lambda with index, object and DoStuff() / to array

Is there a way I can simplify this code? double[] timeline = new double[dataList.Count]; for (int i = 0; i < dataList.Count; i++){ timeline[i] = dataList[i].position; } return timeline; First thought: new…
2
votes
3 answers

Generic list in PagedListAdapter

I want to use generic class as items in PagingList<> interface GenericInterface{} class GenericImplementation: GenericInterface{} As Kotlin doc state: here inheritance in list isn't possible, although I can declare generic type of Parameter of…
2
votes
2 answers

C# generic Interface implementation to derived class

I am stuck in implementation of generic class and interface. I am not sure what i wanted to do is possible or not. here is my code:- I have defined a generic class whose type not define like public class Response { public T Data { get; set;…
Shanu Mehta
  • 182
  • 1
  • 14
2
votes
1 answer

C# populate dictionary value

I'm new to C# and I face a problem that I couldn't resolve. I listen to my Xiaomi gateway to get information. This information comes as two types, report or heartbeat. Report is when something trigger the sensor, as for plug, when you turn it on or…
Furya
  • 413
  • 5
  • 23
2
votes
2 answers

How to make this Java method generic

I have a java method that i'm trying to make generic so that it can take a list of 2 different types of object as a parameter. (Trivial example shown below). These 2 different objects will both always have the methods getDate() and getHour(). The…
Stackman
  • 129
  • 3
  • 14
2
votes
4 answers

Is there a collection in .NET that works as a dictionary and list at the same time?

What I want is basically a collection that's a hybrid of a dictionary and a list. I want a collection that I can add key/value pairs to (like a Dictionary), but at the same be able to retrieve the values (without the keys) in the same order I added…
Truly
  • 23
  • 2
2
votes
5 answers

Creating a generic function in c# that only works with specific types

I am trying to create a Generic function that handles either of my 2 models. Note that both of these models have the same exact properties... For example, in the below code the intellisense has no idea that there is a property called Price in T even…
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
2
votes
1 answer

Java Arraylist remove method takes Object as parameter, not E

For a typed ArrayList list , why isn't remove method is like public boolean remove(E e) { } remove() and contains() method takes Object o as parameter. while add() takes E. There is a likelihood someone can call remove() with different object…
MIK
  • 392
  • 3
  • 19
2
votes
1 answer

Why does Class#getComponentType return null instead of the generic type of ArrayList (Java)?

interface Borrowable { Date getCheckoutDate(); Date getDudeDate(); void setCheckoutDate(Date d); void setDudeDate(Date d); } next class has all the functions that an arraylist has. I have tested all of them and they work perfectly. class…
2
votes
0 answers

How can a cast a void* to a generic struct type whose name differs as per TYPE of argument passed?

I'm trying to simulate the "template" style behavior in C as part of an exercise to refactor code from cpp to C. I constructed a MACRO approach by defining as struct like so: #define FIFO(TYPE, depth, NAME) \ …