13 questions from the last 30 days
3
votes
2
answers
136
views
Java 21 and Generic types wildcard capture issue
I am working on a small side project that uses a very simple command handler pattern for dispatching command classes to handler classes. I come from a C# background, and am running into an issue with ...
3
votes
1
answer
69
views
Conflict on generic TryFrom impl but not on generic From impl
I'm trying to implement TryFrom over a type parameter, like so:
enum MyType {}
struct MyError();
impl<T: Into<u8>> TryFrom<T> for MyType {
type Error = MyError;
fn try_from(...
0
votes
1
answer
87
views
incompatible types: inference variable V has incompatible bounds (SSE / Jackson)
With the deprecation of MappingJacksonValue in spring boot 4/Jackson 3, I'm trying to figure out how to serialize my objects based on a JsonView.
I have the following SSE endpoint :
@GetMapping(...
4
votes
1
answer
99
views
How to type hint class tuple itself not instance without pylance complaining
I'm trying to hint that a Pydantic BaseModel field needs to be the class tuple or one of its subclasses, so I've typed the field as type[tuple]:
from pydantic import BaseModel
class Task1(BaseModel):
...
Advice
0
votes
0
replies
70
views
Generic constraints definitions that are derived/related in TypeScript
function getProp<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
I'm only a week into learning TS, and I was only wondering why this couldn't be written as
function getProp&...
1
vote
0
answers
105
views
How to find fragment interface generic type
I am trying to create a custom generic repository using the fragment interface approach as described in this article: https://docs.spring.io/spring-data/jpa/reference/repositories/custom-...
2
votes
1
answer
68
views
Instantiation of type with recursive type constraints
The Announcing F #7 page gives the example code
type IAddition<'T when 'T :> IAddition<'T>> =
static abstract op_Addition: 'T * 'T -> 'T
type Number<'T when IAddition<'T&...
Advice
3
votes
8
replies
108
views
Implement an interface method with a type parameter
Suppose there's an interface
interface IAnimal {
IFood GetPreferredFood();
}
and a class
class Cat<F>(F food) : IAnimal where F : IFood {
private F _food = food;
public F ...
Best practices
0
votes
1
replies
41
views
How to type a generic SimulationEvent and engine in Python without “TypeVar bound type cannot be generic” errors?
I'm building a simulation engine in Python and want to use generics so that events are strongly typed to a simulation state. I have something like this:
from __future__ import annotations
from abc ...
-1
votes
0
answers
84
views
ASP.NET Core Web API: LinkCollectionWrapper<T>.Values always null in JSON despite being populated
I'm building a HATEOAS implementation in ASP.NET Core using a LinkCollectionWrapper<T> class that wraps a collection of entities and stores links.
My classes look like this:
public class ...
2
votes
1
answer
60
views
Shortcut/Simplification of generic pattern 'X extends Y = Y'?
I find myself having to write X extends Y = Y a lot when creating types in TypeScript, for example:
type T<V extends X = X> = ...
When my types get very long (working on a personalized, type-...
3
votes
1
answer
95
views
Is it possible to dispatch on a "name" object?
I have an object that could be either a "name" or a "call", and I want it to end up as a "call". By a "name" object, I mean like something created by bquote(), ...
Advice
0
votes
1
replies
58
views
Why can a parameter-less anonymous method be assigned to a delegate Action<T> that expects a parameter?
I'm learning about delegates in C# and came across a pattern that I don't fully understand. I have a generic method that returns an Action<T>, which I expect to be a method that accepts one ...