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
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
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); } ```
Comments (0)
No comments yet. Start the discussion.