All Questions
51,717 questions
Advice
0
votes
4
replies
87
views
Generic Type Info at Runtime (Java)
I was reading about Generics from the Eleventh Edition of "Java The Complete Reference", specifically the "Run-Time type Comparisons with a Generic Hierarchy" part.
I was confused ...
Advice
0
votes
8
replies
134
views
How can I allow the user to use class specific methods in generic class T?
I am making a custom LinkedList<T> in Java, as a way to learn more about data structures, and I am trying to make a search method that filters items based on the input, but I ran into an issue. ...
0
votes
1
answer
114
views
While implementing custom stack I got type 'int' must be a reference type in order to use it as parameter 'T' in the generic type or method 'Stack<T>' [closed]
I am getting this error while implementing a stack by myself.
Here is my code
interface IStack<T> where T : class
{
void Push(T item);
T Pop();
T Peek();
bool IsEmpty { get; }
...
1
vote
2
answers
149
views
.NET ReadFromJsonAsync<List<T>>() throws JsonException when API response contains wrapper object
I am developing a layered .NET project with API, BLL, DAL, and UI layers.
The UI layer calls the API using a generic API repository built with HttpClient.
My project structure is roughly like this:
...
1
vote
1
answer
78
views
Using trait bound as type in generics
I'm having trouble with implementing a trait bound generic parameter for an entity that sends messages to a proper entity depending on the message. Imagine a trait called MessageTrait and ...
5
votes
1
answer
87
views
Why does TypeScript distribute conditional types over union types only when the checked type is a naked type parameter?
I’m trying to understand how conditional types behave differently when a type parameter is “naked.” For example:
type Wrapped<T> = [T] extends [string] ? "is string" : "not string&...
1
vote
3
answers
111
views
How to call a method with generic parameter of a self referencing generic interface?
If given a generic interface of which generic is a reference to this generic interface itself, and this interface has a method with parameter as generic type. After implementing this interface with a ...
2
votes
1
answer
155
views
Multiple upper bounds for a generic type parameter
I have an interface and a class in kotlin. For example, interface A and class B.
I want to write a function or a class with generics that will accept as generic all types that are subclasses of both A ...
0
votes
0
answers
46
views
Uncontained snap Carousel with ScrollView
I'm trying to make a generic snap carousel using ScrollView but stuck on over-scroll behavior of the ScrollView. When over-scrolled the re-calculation creates a jittered animation ripple. I want the ...
3
votes
1
answer
64
views
Kotlin removeAll function with MutableCollection receiver - both in/out modifiers are used
In Kotlin, the removeAll extension function on MutableCollection with Iterable argument is defined as (see reference here):
@IgnorableReturnValue
fun <T> MutableCollection<in T>.removeAll(
...
3
votes
2
answers
168
views
How to convert to string an 'allows ref struct' generic argument?
I have a method that accepts a T generic argument. The T has the allows ref struct anti-constraint. Now I want to validate this argument, and in case of failure to include the value of the argument in ...
1
vote
2
answers
170
views
How to make a type depend on a constant generic parameter in Rust?
I am very new to Rust. I want to have a type depend on a constant generic parameter in Rust. In C++, this can easily be achieved with some metaprogramming:
template<std::size_t N>
struct ...
2
votes
1
answer
164
views
iteration over integer range doesn't work with generic type constrainted to integer
Go v1.22 added the ability to easily range from 0 to n-1:
// Prints 0, 1, 2 on separate lines.
for i := range 3 {
fmt.Println(i)
}
However, it doesn't work as expected when the expression's type ...
3
votes
1
answer
99
views
Kotlin plusAssign function on MutableCollection - Array type parameter T not marked as out
In Kotlin, the plusAssign (+=) operator function on MutableCollection with Array argument is defined as (see reference here):
inline operator fun <T>
MutableCollection<in T>.plusAssign( ...
0
votes
1
answer
124
views
How to apply a two-levels' SelectMany using expressions in a generic way in C#
Let's have 3 entities with the same base class for ID's:
public class EntityBase
{
public int Id { get; set; }
}
public class Company : EntityBase
{
public string Brand { get; set; }
public ...