All Questions
Tagged with inheritance generics
1,902
questions
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 ? ...
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 ...
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 ...
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>>{...
-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, ...
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 ...
-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() {
...
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 ...
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; ...
-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 ...
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 ...
-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>
{
...
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 ...
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 ...
-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 ...