IssueRaiser

Abstract static methods

Hi, trying to produce some generic code, I discovered that interfaces can't have non-implemented static methods. But it would be a nice feature to allow this. I can illustrate it by this piece of Rust code: ``` rust struct A { damn: i32 } trait Serializable { fn from_integer(nb: i32) -> Self; } impl Serializable for A { fn from_integer(nb: i32) -> Self { A { damn: nb } } } fn bar<T: Serializable>(nb: i32) -> T { T::from_integer(nb) } pub fn main() { let wow = bar::<A>(10); println!("{}", wow.damn); } ``` I tried to produce a non-working equivalent in Dart: ``` dart abstract class Serializable { static fromInteger(int); } class A implements Serializable { int foo; A(this.foo); A fromInteger(int nb) { return A(nb); } } T bar<T extends Serializable>(int nb) { return T.fromInteger(nb); } main() { var wow = bar<A>(42); print(wow.foo); } ```

Posted by HugoKempfer on May 16, 2019, 2:15 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (Other)

Abstract static methods

HugoKempferMay 16, 2019, 2:15 PM

Hi, trying to produce some generic code, I discovered that interfaces can't have non-implemented static methods. But it would be a nice feature to allow this. I can illustrate it by this piece of Rust code: ``` rust struct A { damn: i32 } trait Serializable { fn from_integer(nb: i32) -> Self; } impl Serializable for A { fn from_integer(nb: i32) -> Self { A { damn: nb } } } fn bar<T: Serializable>(nb: i32) -> T { T::from_integer(nb) } pub fn main() { let wow = bar::<A>(10); println!("{}", wow.damn); } ``` I tried to produce a non-working equivalent in Dart: ``` dart abstract class Serializable { static fromInteger(int); } class A implements Serializable { int foo; A(this.foo); A fromInteger(int nb) { return A(nb); } } T bar<T extends Serializable>(int nb) { return T.fromInteger(nb); } main() { var wow = bar<A>(42); print(wow.foo); } ```

Comments (0)

No comments yet. Start the discussion.

Comment on this issue