dart-lang / dart-lang/language
Abstract static methods
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
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(nb: i32) -> T {
T::from_integer(nb)
}
pub fn main() {
let wow = bar::(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(int nb) {
return T.fromInteger(nb);
}
main() {
var wow = bar(42);
print(wow.foo);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.