51,702 questions
-1
votes
0
answers
24
views
Order of associated generic types in Rust, which one is better?
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) -&...
3
votes
1
answer
155
views
if statement with is operator and Generics fails even when debugger shows correct type
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 ...
3
votes
3
answers
130
views
Symbol not found error with complex generics and lambda arrangement
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 ...
2
votes
1
answer
166
views
How to handle Delphi generic constraint as 'inherits from' class
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 ...
1
vote
1
answer
104
views
Avoid boxing of generic enum type
Given the base class:
public abstract class EnumType<TEnum, TValue>
where TEnum : struct, IConvertible
where TValue : struct
{
public abstract TEnum GetEnumValue(TValue value);
}
...
1
vote
1
answer
79
views
Generic method cannot invoke specialized implementation?
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&...
0
votes
2
answers
229
views
In Delphi, is it possible to create a new generic class from the unconstrained generic base class and a provided type?
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;
...
Advice
0
votes
8
replies
111
views
C# using generic types to represent a partially loaded tree of data
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 ...
5
votes
1
answer
123
views
Rust specifying a trait and associated type are valid for the lifetime inside a function
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, ...
2
votes
2
answers
126
views
C# Pass null to Generic Method Receiving Nullable Type [duplicate]
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 ...
-3
votes
3
answers
251
views
How can I generically convert a String value into an instance of a given Comparable type in Java?
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, ...
1
vote
6
answers
136
views
How do I find out the type of items in a generic type collection?
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 ...
0
votes
0
answers
95
views
Declaring an array of weak referenced protocols gives error: 'Weak' requires that 'any LocationSendingDelegate' be a class type
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 ...
0
votes
0
answers
43
views
Is Swift generic SIMD code much slower than direct SIMD
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<...
0
votes
1
answer
58
views
How to define a generic type with `new(...args)` in TypeScript?
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 {...
1
vote
0
answers
41
views
Issue with generics in Java extending another class and Spring ParameterizedTypeReference
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 ...
1
vote
0
answers
87
views
How to access DbSet properties at runtime [duplicate]
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 ...
2
votes
3
answers
70
views
Is there any way to shorthand multiple parameterised types
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[...
1
vote
3
answers
183
views
Why does Java give a warning for casting Collection<? extends Number> to List<Number> but an error for assignment?
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 = ...
0
votes
1
answer
82
views
Can muli-inheritance be simulated with generic class in C# [closed]
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 ...
3
votes
2
answers
147
views
Map a generic type to an instance of its type
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=...
2
votes
1
answer
136
views
Haskell parameter function that itself has a type parameter
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 -> ...
0
votes
1
answer
75
views
Predicates with generics
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<...
5
votes
3
answers
253
views
Type-annotating function with generics that I don't care about
Suppose I have a class parametrized by a type in Python 3.13:
class Foo[T]: ...
I want to define and type-annotate a method that should work with any Foo[T] instance, regardless of the concrete type ...
1
vote
1
answer
114
views
How to avoid type annotations when using associated types in Rust?
I'm trying to adapt some old sample DSP code from a conference to learn Rust generics. I'm having trouble with E0283 - I want the compiler to infer a type but I don't think my trait implementations ...