Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kosmolot
Created January 1, 2018 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosmolot/a555323baf1d67f473ff9bbf30cc9dd0 to your computer and use it in GitHub Desktop.
Save kosmolot/a555323baf1d67f473ff9bbf30cc9dd0 to your computer and use it in GitHub Desktop.
Wildcards in vala
public class Container<T> : Object {
public T value { get; set; }
public Container (T value) {
_value = value;
}
}
void main () {
Container<void*> obj;
// (Container<void*>) <- required because 'int' is not a pointer type
obj = (Container<void*>) new Container<int>(111);
print("hello %d!\n", ((Container<int>)obj).value); // hello 111!
// (Container<void*>) <- NOT required because 'Container' is a pointer type
obj = new Container<Container<int>>( new Container<int>(222) );
print("hello %d!\n", ((Container<Container<int>>)obj).value.value); // hello 222!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment