Skip to content
This repository has been archived by the owner on Mar 14, 2018. It is now read-only.

Generic classes #16

Open
thosakwe opened this issue Feb 17, 2017 · 0 comments
Open

Generic classes #16

thosakwe opened this issue Feb 17, 2017 · 0 comments

Comments

@thosakwe
Copy link
Collaborator

Once #5 is ready, maybe add generics:

abstract class List<T> {
  size():int;
  add(item:T):void;
  get(index:int):T;
  remove(index:int):T;
}

class ArrayList<T> implements List<T> {
  let _items = T [];

  @override()
  size():int => Lists.size(_items);

  @override()
  add(item:T):void {
    _items = Lists.add(_items, item);
  }

  @override()
  get(index:int):void {
    if (index >= Lists.size(_items))
      throw new RangeError('Out of range');
    return _items[index];
  }

  @override()
  remove(item:T):void {
    // Complex logic...
  }
}

This will probably require a BonoboGenericType that can resolve type parameters, and throw errors if none are defined.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant