Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
38 views

I have a setup like the following from typing import Generic, TypeVar T = TypeVar("T") class ThirdParty: def __init_subclass__(cls): ... # does not call super() class Mine(...
Daraan's user avatar
  • 5,166
-1 votes
2 answers
103 views

public void Test<T>(T reference, T same, T differentOrGreater) { var comparisonInterface = typeof(T) .GetInterfaces() .FirstOrDefault( i => i.IsGenericType &...
codymanix's user avatar
  • 29.6k
0 votes
0 answers
33 views

In my Grails 6 project, I'd like to add an additional feature to select domain classes, so I defined a custom trait. trait MyDomainClassTrait<D> implements GormEntity<D> {} // domain ...
ilPittiz's user avatar
  • 812
0 votes
0 answers
39 views

I have the following function block: FUNCTION_BLOCK FB_GenericsTest VAR_GENERIC CONSTANT SIZE: INT := 1; END_VAR Which has this FB_Init method: METHOD FB_Init: BOOL VAR_INPUT bInitRetains: ...
Apollo3zehn's user avatar
1 vote
1 answer
73 views

Rust newbie here. The following code throws a compiler error: #![feature(portable_simd)] use std::simd::Simd; use std::simd::SimdElement; fn test_mul<T: SimdElement, const N: usize>(x: [T; N]) ...
user1924406's user avatar
Best practices
0 votes
1 replies
55 views

I've got a Matcher interface in Go that is implemented by quite a lot of underlying types. I'd like to restrict the Matcher interface such that implementing types can only be a "collection", ...
mefiX's user avatar
  • 1,347
-1 votes
0 answers
43 views

trait Sub {} trait Super { type SubT: Sub; } // Should we write struct SuperFirst<SUP, SUB> { // Fields are private sup: SUP, sub: SUB, } fn build_1<SUP, SUB>(_: SUP) -&...
Sprite's user avatar
  • 4,157
-2 votes
0 answers
57 views

I am using MudBlazor's MudDataGrid, which functions very similarly to Blazor's QuickGrid. The grid's contents are determined by a RenderFragment parameter called Columns, which contains a list of ...
AAM111's user avatar
  • 1,245
3 votes
1 answer
177 views

I am implementing a message passing mechanism in a multi-threaded Delphi 2010 VCL application. My background threads need to send various DTO records to the main UI thread. I am using a generic ...
Sashko1121's user avatar
2 votes
1 answer
119 views

Take a look at my code: #include <stdio.h> #include <stdlib.h> #define add_int(a, b) ((a) + (b)) typedef struct matrix { int** data; int n_rows; int n_columns; } matrix; ...
PsquareJ Lol's user avatar
3 votes
3 answers
147 views

The following test renders fine in my IDE (Eclipse), but fails to compile when building via Maven. The compiler error is shown in the comment line in the code block below. It looks like the compiler ...
Kevin Day's user avatar
  • 16.6k
3 votes
1 answer
179 views

When trying the following code it will not compile as I receive this error: Type parameter 'T' is not compatible with type TBase I want this type constraint to support the Save method being typed to ...
Richard Shuck's user avatar
2 votes
1 answer
152 views

I am trying to use .NET reflection to emit a class and some interfaces which the class implements. However, I cannot seem to correctly implement the interfaces that are generic, as that results in ...
pmikkelsen's user avatar
1 vote
1 answer
113 views

Given the base class: public abstract class EnumType<TEnum, TValue> where TEnum : struct, IConvertible where TValue : struct { public abstract TEnum GetEnumValue(TValue value); } ...
Weifen Luo's user avatar
Best practices
0 votes
2 replies
44 views

I am expecting that only the first line of main function will be compiled. fun<T> T.shouldBe(arg:T) : Boolean { return this == arg } fun main() { 1.shouldBe(2) 1.shouldBe(true) ...
Nikita Chegodaev's user avatar
1 vote
1 answer
91 views

It is possible to make a call to a specific implementation of a generic method on a struct, ex: impl Printer<i16> { pub fn run() { println!("Specific i16"); } } Printer::<i16&...
Tim's user avatar
  • 4,885
1 vote
1 answer
93 views

Python 3.12 introduced new syntax sugar for generics. What's the new way of writing an upper-bounded generic like this: def foo[T extends Bar](baz: T) -> T: ... Before new syntax features I ...
detectivekaktus's user avatar
2 votes
2 answers
239 views

I want to be able to write a function such as below, but can't get the typeinfo or type reference for the unconstrained generic type of TMyBase<T>. type TBase<T> = class end; ...
Richard Shuck's user avatar
0 votes
0 answers
118 views

I am implementing an ordered list that automatically inserts elements in the correct sorted position using a Comparator. The list is built from scratch (not using java.util.ArrayList) and uses an ...
Raam's user avatar
  • 11
Advice
0 votes
8 replies
114 views

The problem I am trying to solve is representing a partially loaded tree of objects using C# generics. For example, suppose we have the following classes: public class Address { public string ...
Jeremy Salwen's user avatar
4 votes
1 answer
142 views

I have the code below. import React from 'react'; type Button = React.ComponentType<{ size: 's' }>; type Select = React.ComponentType<{ color: string }>; declare const button: Button; ...
Evgen S's user avatar
  • 43
5 votes
1 answer
132 views

I am using the winnow crate to write a parser and am struggling with adding tests due to lifetime conflicts. The basic setup I have is a stateful stream: // The primary stream type type SStream<'i, ...
JohnT's user avatar
  • 115
0 votes
2 answers
109 views

Use case: I want to write a JsonConverter for a generic type like this, but I cannot apply it to the type itself: public class EditingModelConverter<T> : JsonConverter<EditingModel<T>&...
Luke Vo's user avatar
  • 21.6k
2 votes
2 answers
126 views

The following code generates CS1503 with the message: error CS1503: Argument 1: cannot convert from '<null>' to 'T?' public class MyClass<T> where T : notnull { // This is the only ...
Jeff G's user avatar
  • 4,735
-3 votes
3 answers
255 views

I’m trying to implement a generic utility method that takes a String value and a Class<?> type, and returns an instance of that type. The context: This value represents data from a JPA column, ...
David Todorov's user avatar
4 votes
0 answers
106 views

I want to narrow an unambiguously defined dict[...] type in a superclass to a specific TypedDict in an inheriting class but I cannot figure out a way to specify a dict-based supertype that the ...
bossi's user avatar
  • 1,744
2 votes
6 answers
145 views

I want to write a method that converts a collection of generic type elements into a human-readable string. This method should also work with nested collections. I haven't found a better approach than ...
Human's user avatar
  • 63
0 votes
0 answers
94 views

In YamlDotNet source, there is function with a definition of: public static bool Accept<T>(this IParser parser, [MaybeNullWhen(false)] out T @event) where T : ParsingEvent and which is called ...
Peyre's user avatar
  • 635
0 votes
0 answers
96 views

I need to store an array of weak referenced protocols: class Weak<T: AnyObject> { weak var value: T? init (_ value: T) { self.value = value } } protocol ...
sudoExclamationExclamation's user avatar
0 votes
1 answer
87 views

I am extending my C# J2K library to dynamically register codecs from other assemblies. That part is working, but I am having trouble understanding IsAssignableFrom(TypeInfo) and how I can deduce which ...
Cinder Biscuits's user avatar
0 votes
0 answers
49 views

I have written a SIMD interpolator like this: public struct Fade_SIMD8 { public init() {} public func interpolate(_ t: SIMD8<Float>, between a: SIMD8<Float>, and b: SIMD8<...
AirXygène's user avatar
  • 3,061
-3 votes
1 answer
194 views

How would I convert T to INumber? Please see my example below. The problem here is that I need a generic function that does different things depending on whether the type is INumber or not. void Func&...
user3324131's user avatar
1 vote
1 answer
60 views

In TypeScript, it is possible to define a type of a constructable class using new(...args: any): // We have some class inheritance abstract class Something {} class ChildOfSomething extends Something {...
goose_lake's user avatar
  • 1,637
0 votes
1 answer
55 views

I was working on notion like app, so I have a Note(consider as a Page in notion) and in that i am having blocks, where block having different id's and held with Note in Foreign field so now in views ...
sbnd abhijeet's user avatar
1 vote
0 answers
44 views

Using RestTemplate in Spring Boot to connect to a server, I have this generic class to map responses from the server I'm connecting to: @Data public class ServicesResponseDTO<T> implements ...
user2087103's user avatar
3 votes
2 answers
106 views

I am working on a Spring Boot application and there I use JWE - tokens. When generating these tokens I serialize a given DTO. As an example, the generation of an AccessToken looks like this: public ...
LaggyLogic's user avatar
1 vote
0 answers
89 views

I am very new to development with ORMs. In my project, where I use Entity Framework Core, I want to create a class that would encapsulate whole interaction with database, i.e. through which I would ...
Alex's user avatar
  • 11
9 votes
2 answers
189 views

Why does the following cause a compilation error? One Map<Integer, Integer> map = new HashMap<>(); List<Integer> numList = map.entrySet().stream() .sorted(Comparator....
Joshua's user avatar
  • 93
2 votes
3 answers
78 views

Say I have the following trait and classes: trait T[C1, C2, C3, C4] case class A() extends T[Int, Double, Long, String] case class B() extends T[Int, Double, Long, String] case class C() extends T[...
user79074's user avatar
  • 5,412
3 votes
2 answers
135 views

I've created a generic package called Generic_Functions which must be instantiated in similar fashion to the standard Ada.Numerics.Generic_Real_Arrays and has next specification: with Ada.Numerics....
tymurmchyk's user avatar
2 votes
3 answers
190 views

I’m trying to understand the difference between assignment and casting in Java generics. Consider the following examples: List<Integer> ints = new ArrayList<>(); List<Number> nums = ...
AMZ's user avatar
  • 410
3 votes
1 answer
92 views

I already know it's possible to check if a type is a class. func isClass<T>(_ value: T.Type) -> Bool { T.self is AnyClass } func isClass<T>(_ value: T) -> Bool { T.self is AnyClass } ...
Radioactive's user avatar
0 votes
1 answer
82 views

I have several DataGrid (actually an UserControl based on a DataGrid with filtering dialog, etc.) in a WPF project which show ObservableCollection<VisualXModel> entities where VisualXModel ...
Ludovic Wagner's user avatar
18 votes
1 answer
1k views

In C#, using the structure HashCode and the List<T>.ForEach method shows a behaviour that I cannot explain: The two snippets below do not return the same result: Working as expected: var ...
Julian's user avatar
  • 285
3 votes
2 answers
147 views

I have the following inheritance structure: class S: ... class A(S): ... class B(S): ... I'd like to conceptually do something like the following: class Foo: T = TypeVar('T', bound=...
bossi's user avatar
  • 1,744
1 vote
0 answers
75 views

Question In the example below, childOfNumbers is correctly inferred to be Child<number>. However, my issue is childOfStrings is inferred to be Base<string>. Is it possible to have a parent ...
Impurity's user avatar
  • 1,142
2 votes
1 answer
140 views

I'm trying to write a function that performs a binary operation on either floating-point numbers or integers. My attempt: data MyNum = F Float | I Int performBinaryOperation :: (Num a) => (a -> ...
Jacob Lockard's user avatar
3 votes
1 answer
137 views

Go 1.22 introduced iterating over functions with for ... range. I’m trying to make a generator that respects context.Context so that breaking early doesn’t leak a goroutine. package main import ( ...
Fernando Valderrama Guayán's user avatar
1 vote
1 answer
76 views

I’m trying to use Predicate with generics but I keep getting the following compilation error : Cannot convert value of type 'PredicateExpressions.Equal<PredicateExpressions.ConditionalCast<...
Nonouf's user avatar
  • 410
1 vote
1 answer
203 views

I am working with a generic function in Python and trying to understand how to properly check the actual type of a generic parameter to narrow the type of all parameters bound to the same generic type ...
小金貓's user avatar

1
2 3 4 5
1035