Skip to main content

Questions tagged [generics]

Generics are a form of parametric polymorphism found in a range of languages, including .NET languages, Java, Swift, Rust and Go (since 1.18).

0 votes
2 answers
124 views

Can not create Function array in Java 8

I have a class called SFunction which extends from Function in JDK 8 @FunctionalInterface public interface SFunction<T, R> extends Function<T, R>, Serializable { } Now I have several ...
flyingfox's user avatar
  • 13.5k
0 votes
0 answers
21 views

check if given object implements certain generic interface; type argument(s) NOT known [duplicate]

I have some object. I want to check at runtime if it is an IReadOnlyCollection<T> of any T, i.e. I cannot specify that T in my check. So it should return true for e.g. IReadOnlyCollection<...
Kjara's user avatar
  • 2,792
0 votes
1 answer
48 views

Java Generic wildcard misunderstanding [duplicate]

Having this: public <T extends DataAgent> DataProcessor<? extends DataAgent> resolveProcessor( final String response, T dAgent) throws Exception { if (dAgent.getType() ...
piet's user avatar
  • 396
0 votes
1 answer
62 views

Is it possible to mask a reference with an interface without heap allocating?

Having the following two classes interface IMask { string GetName(); } readonly struct StructSource : IMask { string IMask.GetName() { throw new NotImplementedException(); } } ...
James Jonatah's user avatar
0 votes
0 answers
56 views

How to simulate non-type template parameters in C# for generic classes for compile time type safety?

Is there a way to treat integers eg. 3 and 5 as their own types with an additional property being the value they represent? Specifically I want Modulo<3> to be different to Modulo<5> to ...
Mukund Srinivasan's user avatar
0 votes
0 answers
14 views

How do you transform a typescript object to another type, without using type casting? [duplicate]

I have a mapped type that maps strings/numbers/booleans to "tagged" versions of those types: interface TaggedString { type: "string"; value: string; } interface TaggedNumber { ...
lentil-soup's user avatar
0 votes
0 answers
26 views

Type 'any Shape' cannot conform to 'Shape'

I am trying to create different shapes on a card based on the card type in Swiftui. import SwiftUI let shapes: [any Shape] = [Circle(), Rectangle(), Ellipse()] struct CardView: View { var body: ...
Madu's user avatar
  • 4,939
1 vote
1 answer
51 views

Creating generics with delegate protocol type

I am trying to refactor this code: @objc protocol BaseDelegate { func xxx() } protocol DerivedDelegate: BaseDelegate { func yyy() } protocol NextDerivedDelegate: BaseDelegate { func zzz()...
Bawenang Rukmoko Pardian Putra's user avatar
0 votes
0 answers
43 views

SwiftUI store variety of generic functions for custom Table [closed]

Hello im still in my beginning of learning SwiftUI. Currently I try to build a expense tracker myself for some more advanced practice. For that reason I try to replicate a excel like pivot table for ...
Tom's user avatar
  • 1
0 votes
1 answer
12 views

Why is This _Generic Statement Giving an "Expression expected" Error?

I am writing an implementation of a dynamic array in C11. The keyword _Generic comes along with the C11 standard and is supported in my version of GCC (14.1.1) as far as I know. I have worked with it ...
Zenais's user avatar
  • 96
0 votes
1 answer
39 views

Infer the return type based on a parameter

I've a function that takes an action "DELETE"|"RENAME"|"MOVE"|etc... I would like the return type to be different depending on the action fired. For example, "DELETE&...
OtpExhaustv2's user avatar
0 votes
1 answer
53 views

How to a return generic type in go [duplicate]

I'm very new to go, still in the phase of learning and couldn't find any answers matching to my issue, so please don't downvote. I have this generic interface which can be instantiated by two type ...
ansme's user avatar
  • 443
1 vote
1 answer
64 views

How to design events and event handlers system using generic in C#?

I want to create an event system in my ASP.NET Core backend using generics for ease of creation and registration of handlers. The main problem I encountered while trying several solutions was generic ...
idchlife's user avatar
  • 666
1 vote
2 answers
38 views

C# reflection: Get static method with multiple generic overloads [duplicate]

How we can get a method such as Tuple.Create that has multiple generic overloads through reflection and use it with our custom generic type arguments? usecase: the generic type arguments are known ...
Mansoor Omrani's user avatar
2 votes
1 answer
34 views

What’s the meaning of `T extends readonly unknown[] | []` in TypeScript’s function signature of `Promise.all`?

I noticed an interesting (possibly hacking) part in TypeScript’s lib.d.ts: interface PromiseConstructor { /* ... */ /** * Creates a Promise that is resolved with an array of results when all ...
Snowflyt's user avatar
  • 369

15 30 50 per page
1
2 3 4 5
3330