Skip to content

Instantly share code, notes, and snippets.

@paulredmond
Created June 2, 2017 17:31
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 paulredmond/17e0649bdd8c4d355cd980c9cf635ec1 to your computer and use it in GitHub Desktop.
Save paulredmond/17e0649bdd8c4d355cd980c9cf635ec1 to your computer and use it in GitHub Desktop.
Java equivalent example (I think) of the PHP Generics RFC Example
public class Entry<KeyType, ValueType>
{
protected KeyType key;
protected ValueType value;
public Entry(KeyType key, ValueType value) {
key = key;
value = value;
}
public KeyType getKey() {
return key;
}
public ValueType getValue() {
return value;
}
}
<?php
class Entry<KeyType, ValueType>
{
protected $key;
protected $value;
public function __construct(KeyType $key, ValueType $value)
{
$this->key = $key;
$this->value = $value;
}
public function getKey(): KeyType
{
return $this->key;
}
public function getValue(): ValueType
{
return $this->value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment