Skip to content

Instantly share code, notes, and snippets.

@wighawag
Created July 24, 2012 15:49
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 wighawag/3170808 to your computer and use it in GitHub Desktop.
Save wighawag/3170808 to your computer and use it in GitHub Desktop.
Generics Type parameter used as Type Constraint for method Generic Type parameter
package ;
class Main
{
static public function main()
{
var entity = new Entity();
var component0 = entity.get(EntityComponent); // shoudl pass
var component1 = entity.get(TestEntityComponent); // should pass
//var component2 = entity.get(TestModelComponent); // should fail
var model = new Model();
var modelComponent0 = model.get(ModelComponent); // should pass
var modelComponent1 = model.get(TestModelComponent); // should pass
//var modelComponent2 = model.get(TestEntityComponent); // should fail
}
}
class TestModelComponent extends ModelComponent {
public function new() { super(); }
}
class TestEntityComponent extends EntityComponent {
public function new() { super(); }
}
class EntityComponent {
public function new(){}
}
class ModelComponent {
public function new(){}
}
class Entity extends ComponentOwner<EntityComponent> {
public function new() { super(); }
}
class Model extends ComponentOwner<ModelComponent> {
public function new() { super(); }
}
class ComponentOwner<ComponentBaseType> {
public function new()
{
}
public function get < T : ComponentBaseType > (clazz : Class<T>) : T {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment