Skip to content

Instantly share code, notes, and snippets.

@BenGriffiths
Last active August 29, 2015 13:57
Show Gist options
  • Save BenGriffiths/9711091 to your computer and use it in GitHub Desktop.
Save BenGriffiths/9711091 to your computer and use it in GitHub Desktop.
Hack - Generics Example
<?hh
class Box<T>
{
protected T $data;
public function __construct(T $data)
{
$this->data = $data;
}
public function getData(): T
{
return $this->data;
}
}
function main_gen()
{
$gi = new Box(3);
$gs = new Box("Hi");
$ga = new Box(array());
echo $gi->getData()."\n";
echo $gs->getData()."\n";
echo $ga->getData()."\n";
}
main_gen();
// Output:
3
Hi
Array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment