Skip to main content

All Questions

Tagged with
2 votes
0 answers
66 views

Base class not recoginsed while using wild card generic

Why is the below not working? A b1 = new B(); Function<? super B, ? extends A> function = x -> new B(); A apply = function.apply(b1); It gives an error "Required type capture of ? ...
Sijo Kurien's user avatar
0 votes
1 answer
62 views

C# Generic with both notnull and nullable fields

I need a class for a regular tree in the whole project. Sometimes the tree is used with a string key and sometimes with a Guid key. This class should have not null Id and nullable ParentId. If i use ...
Vitaliy Kuznetsov's user avatar
1 vote
1 answer
35 views

Function with subtype argument doesn't cast to a function with a base type argument

I'm trying to implement a middleware for Koa that slightly extends type of state on context, but the extended state doesn't cast successfully to the base state if I try to cast function that uses ...
Philipp Faster's user avatar
1 vote
1 answer
33 views

Can you pass subtypes as function parameters in function arguments?

I'm struggling to understand generic types with inherited types. class EventHubImpl extends EventHub { final Map<EventId, Signal1<Event>> _signals = <EventId, Signal1<Event>>{...
av4625's user avatar
  • 315
-1 votes
1 answer
41 views

How to set up classes for parsing custom data types in C#

I'm working on a saving/loading system, and I'm trying to serialize and deserialize various objects. I'm working in Unity, and I've created one custom class for the game objects and their behaviours, ...
Adam L.'s user avatar
  • 89
0 votes
1 answer
38 views

Pass templated base class generic child to function without restricting by the template type

I have the following problem. I want to create a baseclass with variable type property that is used internally by the base class and classes that inherit from it as follows: public abstract class ...
The amateur programmer's user avatar
-1 votes
2 answers
72 views

How do you cast an generic class into an generic class of object? [closed]

let's say that you have 2 classes: public abstract class Foo<T> { public abstract T DoSomething(); } public class FooInt : Foo<int> { public override int DoSomething() { ...
0xDED's user avatar
  • 3
0 votes
1 answer
53 views

C# Generic Child Parent Child Relationship

I am trying to create a list of typed objects for a project but realized that I'm having trouble creating a new list of parent typed objects and populating it with a list of child typed objects. The ...
Eugene's user avatar
  • 3
1 vote
1 answer
64 views

Cannot implicitly convert list of derived objects to generic IEnumerable<T> where T is a base type

I have a type system like class Base {} class Derived1 : Base {} class Derived2 : Base {} I have also collections of derived types class MyClass { List<Derived1> Derived1Collection { get; ...
Alex34758's user avatar
  • 454
-1 votes
2 answers
61 views

How to call a method on a generic type from inside the generic class?

I have the following classes: public abstract class TableStorageItem { public TableStorageItem() { } } public abstract class TableStorage<T> where T : TableStorageItem, new() { public ...
Olivier MATROT's user avatar
0 votes
0 answers
32 views

Generic "Create" method in .NET Core that creates two entities

I have two .NET Core entities; UserAccount and Customer that has UserAccountId as foreign key. I want to have a one generic method that first creates UserAccount. Then I take UserAccountId from it and ...
amerr-k's user avatar
  • 59
-1 votes
1 answer
59 views

Dotnet class method with generic return type and one generic argument [duplicate]

I try to make a class method when return type is generic and also one of the arguments is generic. The Return type should be generic class Result, which looks like this: public class Result<T> { ...
julianuslemurrex's user avatar
1 vote
1 answer
60 views

Swift Generic Types and Inheritance

I'm creating an app for iOS and I have a function in a view controller called MainVC that has to return another view controller. The view controller that this function has to return inherits from ...
Guillermo García's user avatar
0 votes
1 answer
36 views

Hide generic type arguments behind concrete type results in CS0535

I've a rather academic question: why is it technically not possible to use the following code? // abstractions public record MappingRequest<TContract, TEntity>( TContract Contract, TEntity ...
mu88's user avatar
  • 5,063
-1 votes
1 answer
75 views

Why does my lambda expression compile while the equivalent method reference does not? Is generics the problem or am I the problem?

I am trying to use method references with generic classes and have noticed that I can make it work with the equivalent lambda expression, but not with method references. I'm wondering if someone can ...
PVDM's user avatar
  • 118

15 30 50 per page
1
2 3 4 5
127