-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Easy way to define a inline class
which inherits all members of the base class.
#2854
Labels
feature
Proposed language feature that solves one or more problems
Comments
I really wish something like this was possible. Sometimes I only want to define a superset of operations to a static type. Forwarding the whole constructor is verbose (and in this case I don't really want to create a new class with overhead, just inline it). Example with an extension: // Some syntax to combine "inline + extension" would be perfect but I understand if this is too much to ask
inline class MyCustomMap<K,V> = Map<K,V>;
extension on MyCustomMap<K,V> {
void fancyMethod() => print('Fancy');
}
final Map<int,int> map = {1:1};
map.fancyMethod(); //compile error
final MyCustomMap<int,int> fancyMap = {1,1};
fancyMap.fancyMethod(); //fine |
A modifier might be better to override(?) some members of the base class. inline class LruCache<K, V> {
inherits Map<K, V> map;
static int size = 100;
@override // ?
V? operator [](K key) {
var value = map.remove(key);
if(value != null) {
map[key] = value;
}
return value;
}
@override // ?
void operator []=(K key, V value) {
map.remove(key);
map[key] = value;
if(map.length > size) {
map.remove(map.keys.first);
}
}
} |
Cf. #2506. |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
typedef
is a easy way to define a alias of a type, but it doesn't have separate static type to be completed, inferred or checked.On the other hand,
inline class
doesn't inherit members of base class.I want to have easy way to define a
inline class
which inherits all members of the base class.For example,
The text was updated successfully, but these errors were encountered: