Skip to main content

Questions tagged [generics]

Meta technique, that allows to pospone the setting of the dependable type to the runtime.

1 vote
4 answers
209 views

Due to type erasure, I can't do instanceof T in Java. With that in mind, how do (should) I write, for example, a generic TreeNode (or, more precisely, DefaultMutableTreeNode)? setUserObject() accepts ...
Sergey Zolotarev's user avatar
6 votes
3 answers
1k views

There is a blog post by Eric Lippert where he describes how to define variance. In a general sense, covariance is achieved when the direction of assignment compatibility is preserved. Contravariance ...
Ramza's user avatar
  • 171
0 votes
1 answer
357 views

I have a class where I want to chain certain operations. The class look something like this class MyClass<T> { create<X>(fn: (_: T) => X): MyClass<X> { ... ...
pratZ's user avatar
  • 119
-2 votes
3 answers
854 views

Refer to the highest upvoted answer here for why you should make an IPizza interface with a IPizza.Prepare() method. This is highly upvoted, But I think the answer is flawed. Sure a pizza can be ...
NWoodsman's user avatar
  • 195
1 vote
1 answer
689 views

I'm trying to create an interaction system for a game I'm developing with Unity and C# and I've been struggling with it for a while now. It consists of interactors and interactables. The idea is that ...
Wojtek Wencel's user avatar
3 votes
2 answers
1k views

I've recently found myself using a generics with constraint that a type should inherit from a specific base class, but now I've just realised that this is redundant and unnecessary because the ...
Piotr Golacki's user avatar
0 votes
1 answer
138 views

I'm currently designing an interface for a container that is supposed to store references of different instances that derived from a common supertype. An analogy of it would be as following: Suppose ...
torez233's user avatar
  • 101
1 vote
1 answer
486 views

I currently working on a parser project in C# and have run into problem. I have an entity folder within my project and within it I have: Entity IEntity.cs (defines a contract for entity classes) ...
Vocaloidas's user avatar
0 votes
1 answer
5k views

Abstract The case: Application contains a lot of views with a list of data. Data views (lists of records) have pagination, filtering and sorting options. The user must be able to select a "...
user2190492's user avatar
4 votes
2 answers
9k views

I've written a class that synchronizes a table between two databases using Dapper. The public and private Methods in the class are generic and the generic parameter is the POCO class that is being ...
GisMofx's user avatar
  • 379
0 votes
0 answers
102 views

I have 2 classes that share some properties public class SportsUser { public string errorCode { get; set; } //the sportsuser and SportsAdminUser is from a different database hence the long and ...
pinman's user avatar
  • 11
6 votes
2 answers
1k views

I wrote this valid piece code, which made me wonder if there was a name for it: public class GenericObject<T> { public T Obj { get; set; } } public class DerivedClass: GenericObject<...
Taco's user avatar
  • 1,175
18 votes
7 answers
8k views

YAGNI might tell us, that in the below implementation the generic version is not needed, as long as the function is only used once. But to me personally, it seems, the generic version is more readable ...
Tobias Hermann's user avatar
1 vote
1 answer
125 views

Here is a concrete example of what I'm asking about: MutableList[ImmutableList[Object]] Where ImmutableList is covariant wrt its first parameter, but MutableList is invariant wrt its first parameter. ...
Beks_Omega's user avatar
1 vote
0 answers
455 views

I can easily put together a message handling set of generic apis in C# with the following quick and dirty code: void Main() { var messageClient = new MessageClient(new TestMessageHandler(), new ...
Andez's user avatar
  • 259

15 30 50 per page
1
2 3 4 5
11