Calling a static method from a generic constraint Dart

TheBichour

I'm trying to call a static method from a generic type I receive. Is that even possible?

Furthermore, I apply a Type constraint in order to only manipulate the object from its parent class.

Here is a short example of what I'm trying to achieve:

class A {
  static func() {
    print("A");
  }
}

class B extends A {
  static func() {
    print("B");
  }
}

concret<T extends A>() {
  T.func(); // I expected a print('B')
}

main() {
    concret<B>();
}
lrn

No, it's not possible.

Dart static method invocations are resolved at compile-time, so it's not possible to call them on type variables which only have a value at run-time.

If it was possible, it would be completely unsafe. Anyone can create a class C extending A which does not have a static func member and invoke concret<C>();. Since static members are not inherited, it would have to give you a run-time error, and there is nothing you can do to detect that at compile-time. That is the primary reason why it is not allowed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling method on generic type Dart

From Dev

Calling generic method in dart with nullable argument

From Dev

How to enforce Implements constraint on generic type T in generic Dart method?

From Java

Calling a static method using generic type

From Dev

Calling generic method from viewmodel

From Dev

dart - pulling static methods from generic extensions

From Dev

Calling a non static method from a in a static context

From Java

calling a super method from a static method

From Dev

Calling a MaybeNull generic method from another generic method

From Dev

Calling non-generic method from generic method in C#

From Java

Calling an overloaded java generic method from scala

From Dev

Calling a Generic Method from BaseEntity on unknown object

From Dev

Calling constructor from a subclass method with a generic parameter

From Dev

Calling a generic Java varargs method from Kotlin

From Java

Calling generic static method locally while omitting class name

From Dev

Could not infer generic parameter when calling protocol static method

From Dev

Generic parameter in static method is calling the same class - is there a better option?

From Java

Generic method, equality constraint

From Java

Calling static generic methods

From Dev

Call static method from trait on generic type

From Dev

Call static method from generic type

From Javascript

Calling an overridden static method from parent

From Dev

Calling super static method from designated initializer

From Dev

Calling a static void Java method from JNI

From Dev

Calling a Java static method with generics from Scala

From Java

Calling Java Main method from static block

From Dev

calling static method from inside the class

From Dev

Calling a static method from NSTimer. Is it possible?

From Dev

Calling a static template method from a template function

Related Related

  1. 1

    Calling method on generic type Dart

  2. 2

    Calling generic method in dart with nullable argument

  3. 3

    How to enforce Implements constraint on generic type T in generic Dart method?

  4. 4

    Calling a static method using generic type

  5. 5

    Calling generic method from viewmodel

  6. 6

    dart - pulling static methods from generic extensions

  7. 7

    Calling a non static method from a in a static context

  8. 8

    calling a super method from a static method

  9. 9

    Calling a MaybeNull generic method from another generic method

  10. 10

    Calling non-generic method from generic method in C#

  11. 11

    Calling an overloaded java generic method from scala

  12. 12

    Calling a Generic Method from BaseEntity on unknown object

  13. 13

    Calling constructor from a subclass method with a generic parameter

  14. 14

    Calling a generic Java varargs method from Kotlin

  15. 15

    Calling generic static method locally while omitting class name

  16. 16

    Could not infer generic parameter when calling protocol static method

  17. 17

    Generic parameter in static method is calling the same class - is there a better option?

  18. 18

    Generic method, equality constraint

  19. 19

    Calling static generic methods

  20. 20

    Call static method from trait on generic type

  21. 21

    Call static method from generic type

  22. 22

    Calling an overridden static method from parent

  23. 23

    Calling super static method from designated initializer

  24. 24

    Calling a static void Java method from JNI

  25. 25

    Calling a Java static method with generics from Scala

  26. 26

    Calling Java Main method from static block

  27. 27

    calling static method from inside the class

  28. 28

    Calling a static method from NSTimer. Is it possible?

  29. 29

    Calling a static template method from a template function

HotTag

Archive