Skip to content

Abstract static methods #356

@HugoKempfer

Description

@HugoKempfer

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:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    meta-classesrequestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions