Access of static class method by static generic method

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();
  }
}

Author: Fantashit

2 thoughts on “Access of static class method by static generic method

  1. @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)

    import std.stdio;
    
    class A {
        static foo() {
        	writeln("A.foo");
        }
    }
    
    class A2 : A {
        static foo() {
        	writeln("A2.foo");
        }
    }
    
    class B {
        static foobar(T : A)() {
            T.foo();
        }
    }
    
    void main() {
        B.foobar!A();
        B.foobar!A2();
    }

    Playground https://run.dlang.io

Comments are closed.