Skip to content

How to create a generic instance object? #41927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kaixiang54 opened this issue May 16, 2020 · 2 comments
Closed

How to create a generic instance object? #41927

kaixiang54 opened this issue May 16, 2020 · 2 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). area-sdk Use area-sdk for general purpose SDK issues (packaging, distribution, …). type-question A question about expected behavior or functionality

Comments

@kaixiang54
Copy link

Like the following code:

abstract class Foobar {
    getDefaultInst();
}
class A {
    method1<T extends Foobar>() {
        T t = new T(); // create generic instance.
        return t.getDefaultInst();
    }
}

Thanks!

@srawlins srawlins added type-question A question about expected behavior or functionality area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). area-sdk Use area-sdk for general purpose SDK issues (packaging, distribution, …). labels May 16, 2020
@srawlins
Copy link
Member

srawlins commented May 16, 2020

This is only possibly possible with the mirrors library.

@lrhn lrhn closed this as completed Apr 9, 2025
@eernstg
Copy link
Member

eernstg commented Apr 9, 2025

Here is a proposal that includes support for invoking constructors via type variables: dart-lang/language#4301.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). area-sdk Use area-sdk for general purpose SDK issues (packaging, distribution, …). type-question A question about expected behavior or functionality
Projects
None yet
Development

No branches or pull requests

4 participants