- Dart SDK Version: from https://dartpad.dartlang.org
- Windows (x64)
- Google Chrome 68
I try call static method of class by generic method and it’s not compiling with error:
Error: The method 'foo' isn't defined for the class 'dart.core::Type'
https://dartpad.dartlang.org/a94baf3ef84a6b22827a39aa4c5133b8
class A {
static void foo() {
print('I <3 ');
}
}
class B {
static void bar<T extends A>() {
T.foo();
print('Dart');
}
}
void main() {
B.bar<A>();
}
PS: I doesn’t know, it’s an issue, bug or only question, but I would be glad if it was possible
And it’s normally work in Java!
public class A {
public static void foo() {
System.out.print("I <3 ");
}
}
public class B {
public static <T extends A> void bar() {
T.foo();
System.out.print("Java");
}
}
public class Main {
public static void main(String[] args) {
B.<A>bar();
}
}
It is not possible in Dart to call static methods this way.
@eernstg Thank you very much for your research and detailed answer. I agree, perhaps in real-world problems call static methods by this way really not needed
By the way, I tried DLang and your example works fine in this lang (unlike Java)
Playground https://run.dlang.io