欧洲杯买球

A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [generics]

欧洲杯买球 Generics are a form of parametric polymorphism found in a range of languages, including .NET languages, Java, Swift, and Rust.

Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

Custom generic tuple with unlimited type parameters

I have a custom tuple: from typing import Generic, TypeVar T = TypeVar('T') class MyTuple(tuple, Generic[T]): pass Is there a simple way to make it subscriptable (for type hints) with ...
0
votes
1answer
16 views

TypeScript can't resolve tuple in function generics

I'm trying to use a union type of overloaded functions with generic return type and it seems that TypeScript is lost when a tuple type is passed as a generic: type Fn1<R> = (one: string) => ...
-1
votes
0answers
32 views

Java multiple subtypes and supertypes in the same List

I have a superclass Animal and a subclass Dog. In a third class I have a List which accepts both subtype and supertype objects at the same time. public class foo{ public ArrayList<Animal> ...
-1
votes
3answers
32 views

Java How can a List hold both supertype and subtype at the same time?

I have a class, say Animal and a subclass Dog. I want to have a List named allAnimals that can hold both Animal objects and Dog objects at the same time. Currently, it is set up as List<Animal> ...
1
vote
1answer
24 views

How do i get firestore document id in a generic method?

i am new to swift and i am trying to implement generic method to fetch data from firestore. func fetch<T: Codable>(query: Query, completion:@escaping (Result<[T]?, Swift.Error>) -> ...
0
votes
1answer
24 views

Why can you call some methods without parentheses while for others you must use parentheses (Kotlin)?

In the example below, why is it that I can invoke nums.lastIndex WITHOUT using parentheses (ex. nums.lastIndex) while for nums.isEmpty() I need to use parentheses? fun removeDuplicates(nums: IntArray)...
0
votes
1answer
27 views

Why <? extends V> does not work for comparingByValue method?

In the Java JDK, I noticed that there is a static method in the Map class: public static <K, V extends Comparable<? super V>> Comparator<Map.Entry<K, V>> comparingByValue() { ...
1
vote
1answer
27 views

TypeScript - Restrict keys of an abstract member based on generic enum or string list

I'm having trouble figuring out how to even find the right words to explain what I'm trying to do, so apologies if I mix up terminology. What I'm trying to do is restrict the keys of an object / ...
0
votes
0answers
13 views

Factory converter for Enums implementing a certain interface

In the Spring core doc, it gives an example of how to write a converter factory for an entire class hierarchy, such as classes that extend an Enum. This allows common code to be used to convert ...
0
votes
4answers
42 views

Function<? super T, ? extends Comparable> does not accept objects of super types of T?

I am dealing with the following puzzle. class Product {} static class Fruit extends Product implements Comparable<Fruit> {} class Apple extends Fruit {} Function<? super Fruit, ? extends ...
0
votes
1answer
63 views

looking a way to combine these methods in generic way on same return type

I have got below three methods and they are returning same return type and the only difference among these three methods is that the data is getting retrieved from different tables. Below are those ...
0
votes
1answer
42 views

How to implement a generic interface where type param is Enum and some other type

I'm working with an interface that accepts a type parameter: public interface Container<T> Now I can have a class as such that implements it: public class EnumContainer implements Container&...
1
vote
0answers
69 views

Java 13 Generics

I have the following classes: List.java: package list; public class List<T> { private Node<T> first = null; public List () { this.first = new Node<T>(null); } } ...
0
votes
1answer
30 views

TypeScript: how to access a static method of a generic class

I have an abstract class: export enum SingularPluralForm { SINGULAR, PLURAL }; export abstract class Dog { // ... } And I have a class that extends the abstract class: export class Pug ...
-3
votes
1answer
55 views

Doubts regarding generics in Java

I have a doubt about the generic concept in Java. I need to create a generic stack class that can create a list of multiple types of objects. Doubt Number: Can I create a generic stack class object ...

15 30 50 per page